yem oliv

Greenhorn
+ Follow
since Apr 11, 2012
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
1
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by yem oliv

Mohana Rao Sv wrote:Try this.



yep, works.
thanks
11 years ago
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...