-->
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: "Unable to find <myEntity> with id XXXXX" af
PostPosted: Tue Sep 11, 2007 10:42 am 
Newbie

Joined: Wed Nov 29, 2006 11:38 am
Posts: 5
Hibernate version:3.2.1 (JPA)

Mapping documents:

Code:
@Entity
@Table(name = "T_PARTICIPANT")
@SequenceGenerator(name = "S_PARTICIPANT", sequenceName = "S_PARTICIPANT)
public class Participant implements Serializable {

/** Primary key. */
    @Id
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "S_PARTICIPANT")
    @Column(name = "PARTICIPANT_ID")
    private Integer participantId;

....
}


Code:
@Entity
@Table(name = "T_REQUEST")
@SequenceGenerator(name = "S_REQUEST", sequenceName = "S_REQUEST")
public class Request implements Serializable, AuthorizationVisitable {

    private static final long serialVersionUID = -8876974983488983532L;

    /** Primary key. */
    @Id
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "S_REQUEST")
    @Column(name = "REQUEST_ID")
    private Integer requestId;

    @OneToMany(fetch = FetchType.LAZY)
    @JoinColumn(name = "REQUEST_ID")
    private Set<Participant> participants;

...
}



Code between sessionFactory.openSession() and session.close():

Code:

@Transactional
public Request saveRequest(Request request) {

for (Participant participant : request.getParticipant()) {
if (participant.getParticipantId() == null || participant.getParticipantId() == 0) {
            em.persist(participant);
        } else {
            participant = em.merge(participant);
        }
}

//code

if (request.getRequestId() == null || request.getRequestId() == 0) {
            em.persist(request);
        } else {
            request = em.merge(request);
        }
}

  return request;
}


Full stack trace of any exception that occurs:

Unable to find model.Participant with id XXXX

Name and version of the database you are using: Oracle 10G

Hi,

I try to persist a list of Participants then the Request that contains this list.
If a rollback is called between the two persist, the list of participants is not stored in database but their id have the value of the generated primary key.

The problem occurs when I try to call this method a second time. The list of participant is not persisted but has a not null primary key.

What is wrong in my code then?

Thanks in advance
Py


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.