简体   繁体   中英

Hibernate ID mappings

I am wondering why hibernate maps id's in seperated classes, this is very anoying!

So, I have this table Productlanguages where every row has an id. This id is set to auto increment, so normaly I don't have to add it myself. Yet, the hibernate auto mapping added a new class ProductlanguageId with the following code: http://pastebin.com/Dwy17BX1 .

Now the id of productlanguages is set to an object of this class.

Can anyone tell me why hibernate has created this class and how I should use this class? Cause I realy have no idea.

Edit: I found out this is because the primary key of this table is build up by three columns. You can see this on this screenshot : 在此处输入图片说明

Yet, I still don't know how to create this Id, because the id in the ProductlanguageId class needs to be automaticly generated. Which is not the case. Can anyone tell me how to make sure this is done automaticly?

I have generated the mappings automaticly with netbeans.

Why do you need to use embedded composite IDs? If it's embedded, then you actually can follow both ways - either use fields from the same class (but then you'll have problems eg during getting object by id), or by adding additional class (how you've done it).

But this all is needed only if you're using composite IDs, if your ID is just an integer, you can use native ID generator, you won't need to create a separate class for this.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM