Creating a recursice, hierarchical EJB with CMP and CMR
0 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Anonymous
Posted On:   Thursday, July 4, 2002 02:27 AM

I want to implement a hierarcy using EJB CMP and CMR, ie. I want to have some sort of Entity Bean with an CMR attribute called "parent" and a CMR attribute called children, the latter should get/set a Collection and the former a local interface of a bean of the same type. This way one could easily build tree-structures for all kinds of purposes. However, I have a problem deploying this on the Sun j2ee sdk 1.3.1 (and JBoss 3). The EJB-relationship is set up as a bi-directional 1:* relationship in deploytool, and neither parent nor children are marked as CMP-fields (as they participate in CMR instead). It seems like the j2ee container expects "parent" to be deployed as a CMP-field, because it complains about the generated subc   More>>

I want to implement a hierarcy using EJB CMP and CMR, ie. I want to have some sort of Entity Bean with an CMR attribute called "parent" and a CMR attribute called children, the latter should get/set a Collection and the former a local interface of a bean of the same type.



This way one could easily build tree-structures for all kinds of purposes. However, I have a problem deploying this on the Sun j2ee sdk 1.3.1 (and JBoss 3). The EJB-relationship is set up as a bi-directional 1:* relationship in deploytool, and neither parent nor children are marked as
CMP-fields (as they participate in CMR instead). It seems like the j2ee container expects "parent" to be deployed as a CMP-field, because it complains about the generated subclass-implementation not implementing getParent/setParent methods.



Here is a "summary" of the code for my ThemeEJB:




			

[...]

public abstract class ThemeEJB implements EntityBean
{

[...]

public abstract ThemeLocal getParent();

public abstract void setParent(ThemeLocal parent);

public abstract java.util.Collection getChildren();

public abstract void setChildren(java.util.Collection children);

public void addChild(ThemeLocal theme)
{
getChildren().add(theme);
}

public void addChild(java.lang.String themeKey)
{
try {
Context ic = new InitialContext();
ThemeLocalHome home = (ThemeLocalHome)
ic.lookup("java:comp/env/ThemeEJB");
ThemeLocal theme =
home.findByPrimaryKey(themeKey);
addChild(theme);
} catch (Exception ex) {
ex.printStackTrace();
}
}

public void removeChild(java.lang.String themeKey)
{
try {
Context ic = new InitialContext();
ThemeLocalHome home = (ThemeLocalHome)
ic.lookup("java:comp/env/ThemeEJB");
ThemeLocal theme =
home.findByPrimaryKey(themeKey);
getChildren().remove(theme);
} catch (Exception ex) {
ex.printStackTrace();
}
}

public java.util.ArrayList getChildList()
{
ArrayList list = new ArrayList();
Iterator c = getChildren().iterator();
while (c.hasNext()) {
list.add((ThemeLocal)c.next());
}
return list;
}

[...]

}




I've tried various versions of deployment descriptors here, but no luck. Has anyone actually managed to create a hierarcy using one "recursive" node EJB and CMP/CMR with parent anc children bidirectional 1:* relationships? If so feel free to post me some hints. Thanks in advance.


			
--
jonmartin.solaas@mail.link.no
   <<Less
About | Sitemap | Contact