• Post Reply Bookmark Topic Watch Topic
  • New Topic

Hibernate - Particular Id Generator ?  RSS feed

 
yem oliv
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4001
42
Chrome Fedora Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!