[jboss-user] [EJB 3.0] - Session bean design for accessing tree based entity beans

k34216 do-not-reply at jboss.com
Wed Aug 2 11:10:07 EDT 2006


Hi, I am just getting started with EJB3, and I was working through an example and I can't seem to find a clean way to implement a session bean that access an entity bean which is recursive. 

So lets say our entity bean looks like so: 

@Entity
public class TreeNode {
        @Id
        @GeneratedValue
        long getId();
        void setId(long id);        

        @OneToOne(cascade={CascadeType.REFRESH})
        TreeNode getParent();
         void setParent(TreeNode parent);
         
        @OneToMany(cascade={CascadeType.ALL})
        Collection getChildren();
        void setChildren(Collection children); 
}

And the tree is very large and deep, so using eager loading is not really what we want. 

I have tried a few designs of stateless session beans and it seems like all of them fail the principal of least astonishment - You can't use the getChildren() on the TreeNode after it has been serialized and passed to the client, because the children are lazy loaded. So instead your left having to implement an interface on the session bean for getting the children of a particular node.

I haven't even touched on modifying the tree yet via the session bean :( 

Assuming that we needed a way for the client to examine and modify the tree what might the session bean interface look like? Would it be worth while making it a statefull session bean?


Thanks,

k34216


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

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



More information about the jboss-user mailing list