Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » Copygroup(IllegalStateException: Cannot get unfetched attribute [object] from detached object)
Copygroup [message #902346] Fri, 17 August 2012 08:36 Go to next message
Ida Li is currently offline Ida LiFriend
Messages: 3
Registered: August 2012
Junior Member
Hi,

I use Fetchgroup to retrieve partial data with entity manager, then I use Copygroup to make a copy of partially fetched entity. I got this exception:
IllegalStateException: Cannot get unfetched attribute [accessionAgents] from detached object Accession[ accessionId=7 ].

Please help me.

Thanks,
Ida
Re: Copygroup [message #902451 is a reply to message #902346] Fri, 17 August 2012 16:02 Go to previous messageGo to next message
Chris Delahunt is currently offline Chris DelahuntFriend
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 Go to previous messageGo to next message
Ida Li is currently offline Ida LiFriend
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 Go to previous messageGo to next message
James Sutherland is currently offline James SutherlandFriend
Messages: 1939
Registered: July 2009
Location: Ottawa, Canada
Senior Member

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
Re: Copygroup [message #905091 is a reply to message #905022] Wed, 29 August 2012 17:03 Go to previous message
Ida Li is currently offline Ida LiFriend
Messages: 3
Registered: August 2012
Junior Member
Hi James,

I solved it with reflections. But I still think it will be nice if I can use copygroup. I will try again when I have time.
Previous Topic:setTableQualifier(schema) without transaction
Next Topic:preventing on jpa exception setRollbackOnly
Goto Forum:
  


Current Time: Fri Apr 19 06:02:08 GMT 2024

Powered by FUDForum. Page generated in 0.02368 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top