Upgrading to ejb 3.0 from hibernate 3.0.2 and having many woes.
First issue: Let's say I have a User object, who has a UserStatus, and many Roles. I load the User in one session to a form, it is submitted to be saved in another session.
If i call em.merge(User), I get the TransientObjectException for the UserStatus. ok, makes sense, its dettached. I guess I could remerge mapped object (either manually or through cascade.)
Ok, lets try again... Now we get a SQLGrammarException: could not get next sequence value. Hmm its trying to insert a new UserStatus after I merged. I'm stumped there since it is a reattached entity that already has its ID set.
The only thing i can think of is to reload the UserStatus object before a save with a em.find(). Try again and: voila! that works. Now i look at all the other saves i have and I am depressed thinking of all the reloading i'll have to manually in my code. There has to be a better way, right? I'm missing something obvious I'm sure.
But I move on to be able to update the Roles the user belongs to. I check off a couple of roles in the form, my servlet controller loads the User and the new Roles from the database, and then submits them to the ejb and... great, the roles are there. Now lets uncheck them. Controller loads User, clear()s the set, and on submit we get...
java.sql.BatchUpdateException: Batch entry 0 update system_roles set sysuser_id=null where ..<snip>.. was aborted.
Its trying to null out the roles that are orphaned?? I have a hibernate cascade-delete-orphan annotation on that collection. I fiddle around for another couple hours playing with different combinations of clear()'ing the set and saving, getting rid of the delete-orphan and removing the roles one by one manually, etc.. But always it tries to set the user id foreign key to null when i try to delete a role.
So there are 2 possibilities to the 2 issues i mentioned above:
1) I missed some basic concepts and I need to change the way I am dealing with saving and reattaching objects
2) I am doing things correctly but my mappings/code/whatever is misconfigured.
If its 1) please let me know what I'm doing wrong.
If it is 2) I will try to boil this down to a very simple set of mappings and code and try to post it here and hope for some help.
Thanks in advance for any advice.
|