This week's book giveaway is in the Agile and Other Processes forum.
We're giving away four copies of The Little Book of Impediments (e-book only) and have Tom Perry on-line!
See this thread for details.
Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Hibernate - Particular Id Generator ?

 
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
Pie
Posts: 3930
21
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?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic