openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Alexander Saint Croix" <saintx.opensou...@gmail.com>
Subject Re: OpenJPAQuery getFetchPlan()
Date Thu, 17 Jan 2008 02:05:30 GMT
I figured out what was going on--it WAS in the test case's setUp method.
The ManyToMany reference to the "relationships" field was not reciprocal on
the other end.  So, the files listed below are correct after all!

Sorry for the noise.

Cheers,
--
Alex







On Jan 16, 2008 7:16 PM, Alexander Saint Croix <saintx.opensource@gmail.com>
wrote:

> Hello,
>
> I'm working on trying to pull down an entity as well as two of its
> collection-valued references using a FetchGroup / FetchPlan, and must be
> doing something wrong--I'm getting the entity, but not the items in its
> fetch group.  I'm wondering if anyone could spot-check my work.  Does the
> following scream out for revision?
>
> My entity definition, using a FetchGroup modeled off of the one in the
> user's guide.
>
> @Entity
> > @FetchGroups(
> >         @FetchGroup(name="detail", attributes={
> >         @FetchAttribute(name="assignedResponsibilities"),
> >         @FetchAttribute(name="relationships")}))
> > public class PartyRole<P extends Party>
> >         extends BaseArchetype {
> >
> >     @ManyToOne(cascade = {
> >             CascadeType.PERSIST,
> >             CascadeType.MERGE})
> >     @Column(nullable=false)
> >     @Type( Party.class)
> >     private P party;
> >
> >     @ManyToOne(cascade = {
> >             CascadeType.PERSIST,
> >             CascadeType.MERGE})
> >     @Column(nullable=false)
> >     private PartyRoleType type;
> >
> >     @OneToMany(cascade= CascadeType.ALL)
> >     private Set<AssignedResponsibility> assignedResponsibilities =
> >             new HashSet<AssignedResponsibility>();
> >
> >     @ManyToMany(cascade={
> >             CascadeType.PERSIST,
> >             CascadeType.MERGE},
> >             mappedBy="participants")
> >     @ElementType(PartyRelationship.class)
> >     Set<PartyRelationship<P>> relationships = new
> > HashSet<PartyRelationship<P>>();
> > ...
> > }
> >
>
> The query method in question:
>
> >
> > ...
> >     public List<PartyRole> getPartyRoles(){
> >         Query query = entityManager.createQuery("SELECT a from PartyRole
> > as a");
> >         OpenJPAQuery q = OpenJPAPersistence.cast(query);
> >         q.getFetchPlan().setMaxFetchDepth(2).addFetchGroup("detail");
> >         return q.getResultList();
> >     }
> > ...
> >
>
> Finally, the snippet from my test code.  The line where I call the first
> collection-valued reference (to set name "preMerge relationship") gives me
> "No such element" at the "next()" call.  All else up until that point works
> fine.  This is a common testing pattern I use in my tests to test correct
> MERGE annotation configs, and I'm very confident the problem isn't in the
> test code.
>
>         ...
> >         refresh(partyRoles, partyRoleTypes, parties, partyRelationships,
> > assigResps);
> >         checkListSize(
> >                 pkg(1, 1, 1, 1, 1),
> >                 pkg(partyRoles, partyRoleTypes, parties,
> > partyRelationships, assigResps));
> >
> >         PartyRole<Party> preMerge = null;
> >         PartyRole<Party> postMerge = null;
> >         for(PartyRole item : partyRoles) {
> >             if(item.getID() == initial.getID()) preMerge = item;
> >         }
> >         Assert.assertNotNull(preMerge);
> >
> >         preMerge.setName("preMerge");
> >         preMerge.getParty().setName("preMerge party");
> >         preMerge.getPartyRoleType().setName("preMerge partyRoleType");
> >         preMerge.getRelationships().iterator().next().setName("preMerge
> > relationship");
> >         preMerge.getAssignedResponsibilities().iterator().next().setName("preMerge
> > assigned responsibility");
> >         ...
> >
>
> From what I can glean out of the user's guide, I set up the FetchGroup
> correctly.  Can anyone see something obviously wrong or missing?  FWIW, all
> of the entities in my library already have passed heavy-duty CRUD tests, so
> we know the entities are in there!
>
> Cheers,
> --
> Alexander R. Saint Croix
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message