openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tovarisch <isantamaria+open...@gmail.com>
Subject Same JPQL, different results?
Date Fri, 29 Apr 2011 15:17:54 GMT

Hi all, 

I have a class Node, base for File and Folder. Each Node has a parent and a
Node list, forming a tree structure. To load all the tree, I run this query:

    SELECT n FROM Node n LEFT JOIN FETCH n.children

Once the EntityManager is closed and the entities are detached, all the
relationships are initialized, and I can navigate the relationships on every
Node.

But if I execute the query again using another EntityManager created from
the same EntityManagerFactory, the query returns the same object list, but
once detached, not all the relationships have been initialized.

All OpenJPA parameters are set by default, except openjpa.DetachState =
loaded(LiteAutoDetach=true) 

What am I doing wrong?

Thank you very much!



The test:

			emf = Persistence.createEntityManagerFactory("openjpa");

			EntityManager em = emf.createEntityManager();
			Query query = em.createQuery("SELECT n FROM Node n LEFT JOIN FETCH
n.children");
			List<Node> res = query.getResultList();
			em.close();
			
			em = emf.createEntityManager();
			query = em.createQuery("SELECT n FROM Node n LEFT JOIN FETCH
n.children");
			res = query.getResultList();
			em.close();

The classes:

@Entity 
@Table(name="nodes") 
@Inheritance(strategy=InheritanceType.SINGLE_TABLE) 
@DiscriminatorColumn(name="type",
discriminatorType=DiscriminatorType.STRING) 
public abstract class Node implements Serializable { 

        @Id	
        @GeneratedValue(strategy=GenerationType.TABLE, generator="node") 
        @TableGenerator(name="node", table="idgenerator",
pkColumnName="generator", valueColumnName="lastId", pkColumnValue="node" ) 
        @Column(name="id") 
        private long id; 
        
        @ManyToOne 
        @JoinColumn(name="parentId") 
        private Node parent; 

        @OneToMany(mappedBy="parent", cascade=CascadeType.ALL) 
        @OrderColumn(name="childIndex") 
        private List<Node> children; 


        /* getters & setters & logic methods*/ 

} 


@Entity 
@DiscriminatorValue(value="F") 
public class Folder extends Node implements Serializable { 

        /* ...*/ 
} 

@Entity 
@DiscriminatorValue(value="A") 
public class File extends Node implements Serializable { 

        /* ...*/ 
} 





@Entity 
@Table(name="nodes") 
@Inheritance(strategy=InheritanceType.SINGLE_TABLE) 
@DiscriminatorColumn(name="type",
discriminatorType=DiscriminatorType.STRING) 
public abstract class Node implements Serializable { 

        @Id	
        @GeneratedValue(strategy=GenerationType.TABLE, generator="node") 
        @TableGenerator(name="node", table="idgenerator",
pkColumnName="generator", valueColumnName="lastId", pkColumnValue="node" ) 
        @Column(name="id") 
        private long id; 
        
        @ManyToOne 
        @JoinColumn(name="parentId") 
        private Node parent; 

        @OneToMany(mappedBy="parent", cascade=CascadeType.ALL) 
        @OrderColumn(name="childIndex") 
        private List<Node> children; 


        /* getters & setters & logic methods*/ 

} 


@Entity 
@DiscriminatorValue(value="F") 
public class Folder extends Node implements Serializable { 

        /* ...*/ 
} 

@Entity 
@DiscriminatorValue(value="A") 
public class File extends Node implements Serializable { 

        /* ...*/ 
} 

--
View this message in context: http://openjpa.208410.n2.nabble.com/Same-JPQL-different-results-tp6317274p6317274.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.

Mime
View raw message