Apparently JPA has a problem with @OneToMany(fetch=FetchType.EAGER) relationships. Above error seems to occur whenever there is a multiple of such relationships in a class. BUT I had a problem where even a single relationship gave this error. The funny bit is that I had NO problems till I needed to add a new persistant class, thats when this guy popped up. Before that I DID HAVE MULTIPLE @OneToMany(fetch=FetchType.EAGER) relationships and it worked perfectly!
Frustrations!
Morale of the story : Don'y be lazy! Cut down @OneToMany(fetch=FetchType.EAGER) relationships. Anyways, I don't think its THAT efficient anyways
Welcome to a kyur 4 th *tch
Leave a comment & Thanx 4 comin.
A CURE FOR THE ITCH
That what it says on your heading. It's a name of a song on [LINKIN PARK]'s Reanimation album, this is how they've retitled the hit song on Hybrid Theory
Expalins why I'm doing this. Basically, Kahanawata =)
Showing posts with label jpa hibernate programming java. Show all posts
Showing posts with label jpa hibernate programming java. Show all posts
Sunday, March 09, 2008
JPA Error (on delete) : java.lang.IllegalArgumentException: Removing a detached instance
This is a problem I got while deleting a record.
What I've figured is that you cannot delete a persistent object that you got very earlier (ex: as a result of a relationship of another object)
What's needed to be done is to refetch that object again by using find and delete it.
Solution:
Solves the problem!
What I've figured is that you cannot delete a persistent object that you got very earlier (ex: as a result of a relationship of another object)
What's needed to be done is to refetch that object again by using find and delete it.
Solution:
EntityManager em=CWUtil.getEntityManager();
em.getTransaction().begin();
m=em.find(Membership.class, m.getId()); //<-Fetched again here
em.remove(m); //<-Deleted here
em.getTransaction().commit();
em.close(); Solves the problem!
Subscribe to:
Posts (Atom)