Hibernate - How to retrieve data from table with two primary keys -
The name of my table is store_record in it's "code" and "status" are two primary keys to be hibernate that I To build the class of perseverance. It consists of two sections, first class code and status setter and gator method and other first-class objects and remaining table fields, setter and garter modes. Now my problem is that I want to get data from that table, how can I write a query in Hibernation for this problem using only one primary key (such as code)
My table is like this
Branches of branches; + ---------------------- + ------------- + ------ + ----- + --------- + ------- + | Field | Type | Faucet Key | Default | Extra | + ---------------------- + ------------- + ------ + ----- + --------- + ------- + | Cod_ifsc_bank_branch | Varchar (24) | No | PRI | Faucet | | Txt_bank_branch_name | Varchar (24) | Yes. | Faucet | | Cod_rec_status | Four (1) | No | PRI | A. | | Txt_last_maker_id | Varchar (16) | Yes. | Faucet | | Dat_last_maker | Date | Yes. | Faucet | | | + ---------------------- + ------------- + ------ + ----- + --------- + ------- +
This table has two primary keys which is a 'cod_ifsc_bank_branch' and another is 'cod_rec_status' but I am a primary I want to get the data using the key like 'cod_ifsc_bank_branch' Now how can I write queries in hibernation for this problem
thanks in advance DNMurthy
This is not a primary key, it is actually a composite key and, shaking together Values give you the primary key
You should have only 1 square map for the unit, and another category for composite ID (if you use the hibernate specific feature you can leave it ).
One attribute is not a part of the primary key, from the other general characteristics, and you can use it as a query parameter in the form of other general characteristics. For example:
(not a very accurate mapping, just give you an idea)
@Entity Class Fu {@EmbededId Private FooId id; @column (updateable = false, insertable = false) Private string code; // part of the ID, but you can map again with // updateable, insertable = false @ column (updatable = false, insertable = false); Private FuStatus status; //Ditto} @ Embedded Class Fooid {@ column string code; @columnfuastats status; }
Then there is a query for you like this:
from foo where foo.code = 'SOME_CODE'
< P> or even (not tested, I think it can work) from foo where foo.id.code = 'SOME_CODE'
Comments
Post a Comment