-->
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: findById returning NULL after modifying entity collection
PostPosted: Tue Feb 01, 2011 2:15 pm 
Newbie

Joined: Wed Sep 08, 2010 5:40 pm
Posts: 1
Synopsis:
Hello all, I am at a total loss here: I have an entity (say A) with several One-to-many relationships (all with FetchType.LAZY) to other entities (say B & C). I can load an individual instance of A with a named query (using its ID) and add multiple successive instances of B to its respective Collection in A. This is verified in the database as well as in the app. However, when I load a different instance of A (with a different ID) and perform some work..., then return to re-load the original instance of A my findById named query returns NULL. This only happens after modifying the collection of B, in A.

Also, after adding each instance of B, a HibernateTemplate.merge takes place.

Details:
My 'A' is a DevProject class, my 'B' is a DevProjectComment class.
Here is my OneToMany representation in A:
Code:
@OneToMany(mappedBy = "project", fetch = FetchType.LAZY, cascade = CascadeType.ALL)
@Cascade(org.hibernate.annotations.CascadeType.DELETE_ORPHAN)
public Set<DevProjectComment> getComments() {
   return this.comments;
}

Here is my ManyToOne representation in B:
Code:
@ManyToOne
@JoinColumn(name="project_id")
public DevProject getProject() {
   return this.project;
}

Here is the NamedQuery, defined in A:
Code:
@NamedQuery(
   name = "devProject.findByIdWithCollections",
   query = "select d from DevProject d " +
   "left join fetch d.documents " +
   "left join fetch d.comments " +
   "where d.id=:id"
)


Can anyone see what I cannot?


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.