File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Object Relational Mapping and the fly likes Hibernate - Particular Id Generator ? Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Reply Bookmark "Hibernate - Particular Id Generator ? " Watch "Hibernate - Particular Id Generator ? " New topic
Author

Hibernate - Particular Id Generator ?

yem oliv
Greenhorn

Joined: Apr 11, 2012
Posts: 2
Hi there,
My name is Olivier, this is my first post here. I'm currently working on a supply management system, using Struts, Spring and Hibernate.

I'm struggling to generate an Id, for which I apparently cannot use any strategy from the annotations @GenericGenerator.

Here's the thing :
I have to manage to tables related : command and commandline.

A closer look at commandline :
this object / table has the attributes :
- id_commandline
- id_command (FK)
- id_product (FK)

The three together form my PK.


My problem :
I would like to know which strategy I should use / which annotations, so that :
- when i "save" a new commandline, hibernate selects the max id_commandline for the id_command from commandline, and then adds +1.

NOTA : this implies -and this might be wrong-, that my constructor would be like : new CommandLine(int id_command, int id_product).


What should I do ?
Is there a strategy working out-of-the-box for that matter ?
Should I "create" my own strategy ? How ?




My actual code is quite far from this situation, as for now, i'm not handling any ID in commandline.

If you need further information do not hesitate, i'll be quite reactive as this is a bloking matter ;).


Thanks by advance,
olivier



EDIT :
Maybe I should have a constructor like : new CommandLine(int id_commandline, int_command, int id_product)
and managing the generation of id_commandline with java code, instead of letting Hibernate handle it.
this looks easier...
Vijitha Kumara
Bartender

Joined: Mar 24, 2008
Posts: 3670

when i "save" a new commandline, hibernate selects the max id_commandline for the id_command from commandline, and then adds +1.

Can you elaborate this more?


SCJP 5 | SCWCD 5
[How to ask questions] [Twitter]
 
I agree. Here's the link: http://jrebel.com/download
 
subject: Hibernate - Particular Id Generator ?
 
Similar Threads
Non numeric id mapping
Correct usage of @AttributeOverride on embedded class
Designing in Hibernate
Criteria on joining fails
Hibernate - Mapping foreign keys tables