This content has been marked as final.
Show 4 replies
-
1. Re: regarding @PrePersist and ID assignment
jaikiran Apr 30, 2008 4:35 AM (in response to mnrz)"mnrz" wrote:
Hi all
I have an entity in which I need to assign my own ID to its primary key,
I put the code to extract the id and set it to the field in a PrePersist method,
You should be setting the id before calling persist. Why are you trying to do that in a callback method? -
2. Re: regarding @PrePersist and ID assignment
mnrz Apr 30, 2008 5:32 AM (in response to mnrz)"jaikiran" wrote:
You should be setting the id before calling persist. Why are you trying to do that in a callback method?
thanks for your reply, the thing is that I want to calculate the ID from a formula in which I use an algorithm. however, if I set any field other than ID it won't work as well -
3. Re: regarding @PrePersist and ID assignment
jaikiran Apr 30, 2008 10:08 AM (in response to mnrz)"mnrz" wrote:
the thing is that I want to calculate the ID from a formula in which I use an algorithm. however, if I set any field other than ID it won't work as well
I probably am not understanding the requirements of your application correctly. Can't you calculate the ID from the formula using your algorithm, before calling the persist method on entity manager? What i am trying to understand is why does the ID calculation or setting any other field be part of the callback method. -
4. Re: regarding @PrePersist and ID assignment
mnrz Apr 30, 2008 1:20 PM (in response to mnrz)well, because my DAO classes may be called from any client and each developer may call them from there codes so I don't want to compel them to calculate the id each time they are using my service classes or force them to set some fields that are not necessary from their point of view.