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
_______________________________________________
jboss-user mailing list
[email protected]
https://lists.jboss.org/mailman/listinfo/jboss-user

Reply via email to