|
Re: Copygroup [message #902451 is a reply to message #902346] |
Fri, 17 August 2012 16:02 |
Chris Delahunt Messages: 1389 Registered: July 2009 |
Senior Member |
|
|
More information is needed, but as the exception states, it is thrown when accessing an unfetched attribute on a detached object. Are you accessing something from your clone, or is this occuring within the clone process itself? If this is within the clone, it means that the copy group includes the accessionAgents field while the fetch group did not, and the entity is detached so that the session is null or unavailable to use to fetch it.
Regards,
Chris
[Updated on: Fri, 17 August 2012 16:05] Report message to a moderator
|
|
|
Re: Copygroup [message #902475 is a reply to message #902451] |
Fri, 17 August 2012 19:57 |
Ida Li Messages: 3 Registered: August 2012 |
Junior Member |
|
|
Hi Chris,
Thanks for quick replay. Here is the code, the Accession and Accessionagent are entity beans. It is one to many relationship. The fields are partial data need to fatch from Accession and the related entities, but the Accessionagent is not in fetch group. The exception occurs during the copy process.
@Entity
@Table(name = "accession")
@XmlRootElement
public class Accession extends BaseEntity {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Basic(optional = false)
@Column(name = "AccessionID")
private Integer accessionId;
@OneToMany(mappedBy = "accession", cascade= {CascadeType.PERSIST, CascadeType.MERGE}, orphanRemoval=true)
private Collection<Accessionagent> accessionAgents;
...
}
@Entity
@Table(name = "accessionagent")
@XmlRootElement
public class Accessionagent extends BaseEntity {
...
@JoinColumn(name = "AccessionID", referencedColumnName = "AccessionID")
@ManyToOne(cascade={CascadeType.MERGE, CascadeType.PERSIST})
private Accession accession;
...
}
public Accession getPartialData(List<String> fields, int id) {
Query query = entityManager.createNamedQuery("Accession.findByAccessionID");
query.setParameter("accessionID", id);
FetchGroup group = new FetchGroup();
CopyGroup cg = new CopyGroup();
cg.setDepth(3);
for(String field : fields) {
group.addAttribute(field);
cg.addAttribute(field);
}
query.setHint(QueryHints.FETCH_GROUP, group);
Accession accession = (Accession) query.getSingleResult();
JpaEntityManager nativeEM = entityManager.unwrap(JpaEntityManager.class);
Accession copyEntity = (Accession) nativeEM.copy(accession, cg);
return copyEntity;
}
Ida
|
|
|
Re: Copygroup [message #905022 is a reply to message #902475] |
Wed, 29 August 2012 15:07 |
|
Can you include the full stack to the exception.
Try a simpler test to see if CopyGroup is working as you expect it.
Note that you should not be setting cg.setDepth(3), but this should not matter as the addAttribute calls setDepth(CASCADE_TREE)
James : Wiki : Book : Blog : Twitter
|
|
|
|
Powered by
FUDForum. Page generated in 0.02368 seconds