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_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,
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...