-->
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.  [ 2 posts ] 
Author Message
 Post subject: EntityNotFoundException when merge
PostPosted: Wed Mar 16, 2011 7:49 am 
Newbie

Joined: Wed Mar 16, 2011 7:41 am
Posts: 1
Hello,

I'm getting lost trying to map an association class with extra attributes. I found some mapping exemple on the net but i got a problem when i try to merge the entities in cascade.

I use this code :
Code:
@Test
  public final void testAddingTravelWithMember(){
    TravelRequest travelRequest = new TravelRequest();
   
    RequestMember requestMember = new RequestMember();
    requestMember.setTravelRequest(travelRequest);
    requestMember.setMember(member);
   
    travelRequest.getRequestMembers().add(requestMember);
    member.getRequestMembers().add(requestMember);
   
    travelRequest = emTest.update(travelRequest);
    Assert.assertNotNull(travelRequest.getTravelRequestId());
  }


and I got the following exception :
Code:
javax.persistence.EntityNotFoundException: Unable to find com.traveldoo.ejb.entities.RequestMember with id com.traveldoo.ejb.entities.RequestMemberPk@a0c486
   at org.hibernate.ejb.Ejb3Configuration$Ejb3EntityNotFoundDelegate.handleEntityNotFound(Ejb3Configuration.java:133)
   at org.hibernate.event.def.DefaultLoadEventListener.load(DefaultLoadEventListener.java:233)
   at org.hibernate.event.def.DefaultLoadEventListener.proxyOrLoad(DefaultLoadEventListener.java:285)
   at org.hibernate.event.def.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:152)
...


I use this code :
Code:
@Entity
@Table(name = "TRAVEL_REQUEST")
public class TravelRequest implements Serializable {
  private static final long serialVersionUID = 1L;

  @Id
  @Column(name = "TRAVEL_REQUEST_ID", unique = true, nullable = false, precision = 10)
  @GeneratedValue(generator = "SEQUENCE_TRAVEL_REQUEST_ID")
  @SequenceGenerator(name = "SEQUENCE_TRAVEL_REQUEST_ID", sequenceName = "SEQUENCE_TRAVEL_REQUEST")
  private Long travelRequestId;

...

  @OneToMany(mappedBy = "travelRequest")
  private List<RequestAction> actions = new ArrayList<RequestAction>();

  @OneToMany(mappedBy = "travelRequest")
  private List<RequestMember> requestMembers = new ArrayList<RequestMember>();

...


The association entity :
Code:
@Entity
@Table(name = "REQUEST_MEMBERS")
public class RequestMember implements Serializable {
  private static final long serialVersionUID = 1L;

  @EmbeddedId
  private RequestMemberPk pk = new RequestMemberPk();

  @ManyToOne
  @JoinColumn(name = "TRAVEL_REQUEST_ID", insertable = false, updatable = false)
  private TravelRequest travelRequest;

  @ManyToOne
  @JoinColumn(name = "MEMBER_ID", insertable = false, updatable = false)
  private Member member;

...


the primary key :
Code:
@Embeddable
public class RequestMemberPk implements Serializable {
  private static final long serialVersionUID = 5089975622327078543L;

  @Column(name = "TRAVEL_REQUEST_ID", nullable = false)
  private Long travelRequestId;

  @Column(name = "MEMBER_ID", nullable = false)
  private Long memberId;

...


The other entity used in pk :
Code:
@Entity
@Table(name = "MEMBER")
public class Member implements Serializable {
  private static final long serialVersionUID = 1L;

  @Id
  @Column(name = "MEMBER_ID", unique = true, nullable = false, precision = 10)
  @GeneratedValue(generator = "SEQUENCE_MEMBER_ID")
  @SequenceGenerator(name = "SEQUENCE_MEMBER_ID", sequenceName = "SEQUENCE_MEMBER")
  private Long memberId;
...

  @OneToMany(mappedBy = "member", cascade = ALL)
  private List<Profile> profiles = new ArrayList<Profile>();

  @OneToMany(mappedBy = "member")
  private List<RequestMember> requestMembers = new ArrayList<RequestMember>();

...


If you got some ideas, please tell me!! ;)


Top
 Profile  
 
 Post subject: Re: EntityNotFoundException when merge
PostPosted: Wed Mar 16, 2011 8:44 am 
Regular
Regular

Joined: Fri Jan 28, 2011 11:44 am
Posts: 117
I think your problem comes from here:
Code:
@EmbeddedId
private RequestMemberPk pk = new RequestMemberPk();

You shouldn't initialize the PK with a call to new!


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

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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.