-
1. Re: How do I use EntityManager in a Bean with foreign key constraints
mvidal0001 Mar 9, 2008 3:33 PM (in response to pete007)Hi
why your EntityManager is @IN ?
normally it should be something like this :
@PersistenceContext
private EntityManager em;
it seems you're initiating twice the same array : oldPS
hope this help.
regards -
2. Re: How do I use EntityManager in a Bean with foreign key constraints
pete007 Mar 9, 2008 3:50 PM (in response to pete007)I think, I've read it somewhere and it worked, now changed it to @PersistenceContext, thanks. .. erm, and the double initiation was only a typo from simplifying the question.
My Problem is still there, the persons don't seem to get deleted, and the constraint fails.
I think, I have to do something between the deletes and the removes, but what?
-
3. Re: How do I use EntityManager in a Bean with foreign key constraints
mvidal0001 Mar 9, 2008 4:08 PM (in response to pete007)May be you can try em.flush() and em.refresh() between the two
I don't think you need a stateful bean for this kind of component.
May be the problem is that you have the same person twice in your csv file :o)
-
4. Re: How do I use EntityManager in a Bean with foreign key constraints
pete007 Mar 9, 2008 7:28 PM (in response to pete007)
matthieu vidal wrote on Mar 09, 2008 04:08 PM:
May be the problem is that you have the same person twice in your csv file :o)This one really shocked me, but fortunately I wasn't that stupid. :D .. After calming down a bit I tried the em.flush() and it worked, although I don't understand, why I must flush the context after removing objects to be able to insert objects with the same business key again??
Thanks a lot, Peter
-
5. Re: How do I use EntityManager in a Bean with foreign key constraints
keithnaas Mar 9, 2008 9:15 PM (in response to pete007)Peter,
I'm not sure about the internal workings of the entity manager, but if I were coding up a JPA implementation, I would likely have done the same thing since its likely easier to code.
Should the em assume that a delete/insert in one transaction is an update? What happens with cascades?
Seems a little squirrely to deal with this scenario in an automated manner.
-
6. Re: How do I use EntityManager in a Bean with foreign key constraints
pete007 Mar 9, 2008 9:47 PM (in response to pete007)Okay, I see this point, but then it should either try to update the current element to save some time/resources or to do both delete and insert operations with the consequence of losing all references. My newly created person e.g doesn't have the same references as the old one. In my app, it tried to insert a second element with the same business key, which is not so easy to understand, particularily for newbies like me. ;)
-
7. Re: How do I use EntityManager in a Bean with foreign key constraints
keithnaas Mar 9, 2008 10:03 PM (in response to pete007)Its definitely not obvious how the behavior will work.
I did find HHH-2801 which might be related to this.