-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Issue persisting "detached" entities
PostPosted: Thu Apr 28, 2011 12:10 pm 
Newbie

Joined: Thu Apr 28, 2011 11:53 am
Posts: 4
I have a RequestEntity with these fields:
Code:

   @NotNull
   @ManyToOne(fetch=FetchType.EAGER, cascade={CascadeType.MERGE, CascadeType.PERSIST})
   @JoinColumn(name="request_type", referencedColumnName="id")
   private RequestTypeEntity requestType;

   @ManyToOne(fetch=FetchType.EAGER, cascade={CascadeType.MERGE, CascadeType.PERSIST})
   @JoinColumn(name="item_source_type", referencedColumnName="item_source_type_name")
   private ItemSourceTypeEntity itemSourceType;


Each of the relationships is presented to the user as a selectOneMenu in an xhtml page with lists of values from the DB. Pretty standard scenario.

When I persist the request, the requestType is set and saved properly. When the request is redisplayed, the correct requestType is preselected and displayed to the user.

The itemSourceType and itemSource, however, don't work. When I call (in my RequestDaoImpl class):

Code:
getEntityManager().persist(request);


I get the hibernate exception:

Code:
Caused by: org.hibernate.PersistentObjectException: detached entity passed to persist: org.aero.libreq.entity.ItemSourceEntity


Prior to the call to persist, I do the following:

Code:
...
request.setRequestType(getEntityManager().merge(request.getRequestType()));if (request.getItemSourceType() != null)
   request.setItemSourceType(getEntityManager().merge(request.getItemSourceType()));
if (request.getItemSource() != null)
   request.setItemSource(getEntityManager().merge(request.getItemSource()));
...


I see no difference between the itemSourceType and requestType setup, so I am confused as to why I am getting this error? When the request is saved, the itemSourceType is not persisted.

The differences between the relationships in the logic are that:
1) The requestType is required and has a default value when the request is first created.
2) the itemSourceType is not required and cannot be populated when the request is first created. It is added to the request in a subsequent update.

How can I properly set up these entities so that the updates to them are properly saved and refreshed for redisplay to the user?

Thank you for any help!!

Oh, and I have stepped through in the debugger and can see that request.itemSourceType is there with all the right values, as is requestType. The exception occurs right when persist is called.


Ginni


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.