-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: bidirectional OneToMany throws LazyInitializationException
PostPosted: Fri Jun 22, 2007 7:23 am 
Newbie

Joined: Fri Jun 22, 2007 7:14 am
Posts: 5
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

Code:
@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:
Code:
@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

Code:
@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:

Code:
@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[/code]


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.