[jboss-user] [Persistence, JBoss/CMP, Hibernate, Database] - bidirectional OneToMany throws LazyInitializationException

beligum do-not-reply at jboss.com
Fri Jun 22 07:50:42 EDT 2007


Hi all, 

I've a specific problem with my EJB3 Hibernate code (using Seam, but I don't think this has anything to do with it).

This is my case:

I have a superclass entity bean: DefaultAccessControlList


  | @Entity
  | @Table(name="access_control_list")
  | @Inheritance(strategy=InheritanceType.SINGLE_TABLE)
  | @DiscriminatorColumn(
  |     name="type",
  |     discriminatorType=DiscriminatorType.STRING
  | )
  | @DiscriminatorValue("default")
  | public class DefaultAccessControlList implements Serializable
  | {
  |     //-----CONSTANTS-----
  |     private static final long serialVersionUID = -1406511547129599450L;
  | 
  |     //-----VARIABLES-----
  |     protected int id;
  | 
  |     //-----CONSTRUCTORS-----
  |     public DefaultAccessControlList()
  |     {
  |     }
  | 
  |     //-----GETTERS/SETTERS------
  |     @Id
  |     @GeneratedValue(strategy = GenerationType.AUTO)
  |     public int getId()
  |     {
  |         return id;
  |     }
  |     protected void setId(int id)
  |     {
  |         this.id = id;
  |     }
  | 

with two subclasses:

  | @Entity
  | @Name("principalAccessControlList")
  | @DiscriminatorValue("principal")
  | public class PrincipalAccessControlList extends DefaultAccessControlList implements Serializable
  | {
  |     //-----CONSTANTS-----
  |     private static final long serialVersionUID = -6044077966387630697L;
  | 
  |     //-----VARIABLES-----
  |     private Inode inode;
  | 
  |     //-----CONSTRUCTORS-----
  |     public PrincipalAccessControlList()
  |     {
  |     }
  | 
  |     //-----GETTERS/SETTERS------
  |     @ManyToOne(targetEntity=AbstractInodeImpl.class)
  |     @JoinColumn(name="inode")
  |     public Inode getInode()
  |     {
  |         return inode;
  |     }
  |     public void setInode(Inode inode)
  |     {
  |         this.inode = inode;
  |     }
  | }
  | 

and


  | @Entity
  | @Name("groupAccessControlList")
  | @DiscriminatorValue("group")
  | public class GroupAccessControlList extends DefaultAccessControlList implements Serializable
  | {
  |     //-----CONSTANTS-----
  |     private static final long serialVersionUID = -2681771597593712778L;
  |     
  |     //-----VARIABLES-----
  |     private Inode inode;
  | 
  |     //-----CONSTRUCTORS-----
  |     public GroupAccessControlList()
  |     {
  |     }
  | 
  |     //-----GETTERS/SETTERS------
  |     /**
  |      * Note: this side is the owner side of this relationship
  |      */
  |     @ManyToOne(targetEntity=AbstractInodeImpl.class)
  |     @JoinColumn(name="inode")
  |     public Inode getInode()
  |     {
  |         return inode;
  |     }
  |     public void setInode(Inode inode)
  |     {
  |         this.inode = inode;
  |     }
  | }
  | 

These beans are the owning side of the Inode-ACL relationship, and the Inode (abstract) class is like this:


  | @Entity
  | @Table(name="inode")
  | @Inheritance(strategy=InheritanceType.SINGLE_TABLE)
  | @DiscriminatorColumn(
  |     name="type",
  |     discriminatorType=DiscriminatorType.STRING
  | )
  | public abstract class AbstractInodeImpl implements Inode
  | {
  |     ...
  | 
  |     @OneToMany(mappedBy="inode")
  |     public List<PrincipalAccessControlList> getPrincipalAccessControlLists()
  |     {
  |         return principalAccessControlLists;
  |     }
  |     public void setPrincipalAccessControlLists(List<PrincipalAccessControlList> principalAccessControlLists)
  |     {
  |         this.principalAccessControlLists = principalAccessControlLists;
  |     }
  |     @OneToMany(mappedBy="inode")
  |     public List<GroupAccessControlList> getGroupAccessControlLists()
  |     {
  |         return groupAccessControlLists;
  |     }
  |     public void setGroupAccessControlLists(List<GroupAccessControlList> groupAccessControlLists)
  |     {
  |         this.groupAccessControlLists = groupAccessControlLists;
  |     }
  | 
  |     ...
  | }
  | 

The problem is that, when I fetch an Inode-object, the reverse-relationship methods getGroupAccessControlLists() and getPrincipalAccessControlLists() are mixed up, and one of them throws an "org.hibernate.LazyInitializationException: illegal access to loading collection" exception when accessed.

Any ideas?

bram

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4056830#4056830

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4056830



More information about the jboss-user mailing list