Composite Entity - EJB 2.0 - CMR

Isn't it possible to make at tree structure with one Entity EJB which has a one-to-many relation to it self. For example a NodeBean that has a one-to-many local relation to it self. I tried to deploy it on Suns RI 1.3.1 without any luck. I got the following message:

Compilation failed.

at com.sun.ejb.codegen.GeneratorDriver.compileClasses(GeneratorDriver.java:232)

at com.sun.ejb.codegen.GeneratorDriver.preDeploy(GeneratorDriver.java:603)

at com.sun.enterprise.tools.deployment.backend.JarInstallerImpl.deployEjbs(JarInstallerImpl.java:707)

at com.sun.enterprise.tools.deployment.backend.JarInstallerImpl.deployApplication(JarInstallerImpl.java:221)

at org.omg.stub.com.sun.enterprise.tools.deployment.backend._JarInstallerImpl_Tie._invoke(Unknown Source)

at com.sun.corba.ee.internal.corba.ServerDelegate.dispatch(ServerDelegate.java:355)

at com.sun.corba.ee.internal.iiop.ORB.process(ORB.java:255)

at com.sun.corba.ee.internal.iiop.RequestProcessor.process(RequestProcessor.java:84)

at com.sun.corba.ee.internal.orbutil.ThreadPool$PooledThread.run(ThreadPool.java:99)

I don't have any problems with all other type of relations between different beans.

I have solved it in a 'hacky' way, but why doesn't it work the right way?

[1322 byte] By [ThomasMA10] at [2007-9-26 22:59:26]
# 1

[ is it ] possible to make at tree structure with one Entity EJB which has a one-to-many relation to it self.

It is possible, but not advisable because it follows two Anti-Patterns 1) Directly mapping each Business Model Object to an EJB. 2) Requires Client to aggregate data from multiple requests.

This is a problem because, because EJB are much heavier weight that plain Value Object Beans, and a changes to the EJB requires changes to the client.

Consider making the Composite, or a sub-set of it, a value object .

MartinS. at 2007-7-4 3:49:41 > top of Java-index,Other Topics,Patterns & OO Design...
# 2

With EJB 2.0 it's now feasible to make fine grained EJB's due to the

possibility of making local lookups. I agree that EJB 1.1 emphazises

course grained EJB's where direct mapping of the Business model is a

bad idea. With a Session Bean as a remote facade to local Entity Beans

there are no client issues. Therefore a local Entity Bean with reference

to itself should be fairly light weight. I use that construction with other

local Entity Beans, that have CMR's to each other without any problems.

My problem is, that Sun's RI doesn't allow me to deploy a local Entity

bean with a CMR to itself. How do I do that?

ThomasMA10 at 2007-7-4 3:49:41 > top of Java-index,Other Topics,Patterns & OO Design...
# 3

I have exactly the same problem with a many-to-many self-relation on an entity bean.

I get awful exceptions when trying to deploy it on Sun's RI. (haven't tried with other servers).

The fact is that the exception I get is the same as when one tries to update CMR fields in an ejbCreate method.

I would be happy to have more informations on this topic.

mitch6a2 at 2007-7-4 3:49:41 > top of Java-index,Other Topics,Patterns & OO Design...
# 4
It is a bug which is already reported (Bug Id 4634039 in the Bug Database).
dirkeiden at 2007-7-4 3:49:41 > top of Java-index,Other Topics,Patterns & OO Design...
# 5

The bug already was reported Feb 06, 2002 and has received only 10 votes in the bug parade, although it is an obvious and fundamental error when implementing EJB 2.0.

Further on a representative faulty generated descriptor by the deploytool

<join-object>

<name>de.kamuc.osv.ejb.course.CourseEJB_courseQualifyingFor_CourseEJB_prerequisiteCourse</name>

<ejb20-cmp>

<sql-statement>

<operation>storeRow</operation>

<sql> </sql>

</sql-statement>

<sql-statement>

<operation>findBySourceKey</operation>

<sql>SELECT "_CourseEJBPMPrimaryKey" FROM "CourseEJB_courseQualifyingFor_CourseEJB_prerequisiteCourseTable" WHERE </sql>

</sql-statement>

<sql-statement>

<operation>deleteRow</operation>

<sql>DELETE FROM "CourseEJB_courseQualifyingFor_CourseEJB_prerequisiteCourseTable" WHERE "_CourseEJBPMPrimaryKey" = ? </sql>

</sql-statement>

<sql-statement>

<operation>loadRow</operation>

<sql>SELECT * FROM "CourseEJB_courseQualifyingFor_CourseEJB_prerequisiteCourseTable" WHERE "_CourseEJBPMPrimaryKey" = ? </sql>

</sql-statement>

<sql-statement>

<operation>findByPrimaryKey</operation>

<sql>SELECT "_CourseEJBPMPrimaryKey" FROM "CourseEJB_courseQualifyingFor_CourseEJB_prerequisiteCourseTable" WHERE "_CourseEJBPMPrimaryKey" = ? </sql>

</sql-statement>

<sql-statement>

<operation>createRow</operation>

<sql>INSERT INTO "CourseEJB_courseQualifyingFor_CourseEJB_prerequisiteCourseTable" ( "_CourseEJBPMPrimaryKey" ) VALUES ( ? )</sql>

</sql-statement>

<sql-statement>

<operation>deleteTable</operation>

<sql>DROP TABLE "CourseEJB_courseQualifyingFor_CourseEJB_prerequisiteCourseTable"</sql>

</sql-statement>

<sql-statement>

<operation>createTable</operation>

<sql>CREATE TABLE "CourseEJB_courseQualifyingFor_CourseEJB_prerequisiteCourseTable" ("_CourseEJBPMPrimaryKey" LONGINT, CONSTRAINT "pk_CourseEJB_courseQualifyingFor_CourseEJB_prerequisiteCourseTabl" PRIMARY KEY ("_CourseEJBPMPrimaryKey") )</sql>

</sql-statement>

<sql-statement>

<operation>findBySinkKey</operation>

<sql>SELECT FROM "CourseEJB_courseQualifyingFor_CourseEJB_prerequisiteCourseTable" WHERE "_CourseEJBPMPrimaryKey" = ? </sql>

</sql-statement>

<create-table-deploy>true</create-table-deploy>

<delete-table-undeploy>true</delete-table-undeploy>

</ejb20-cmp>

<source>

<name>CourseEJB</name>

<field>courseQualifyingFor</field>

</source>

<sink>

<name>CourseEJB</name>

<field>prerequisiteCourse</field>

</sink>

</join-object>

Dirlewanger_Klaus at 2007-7-4 3:49:41 > top of Java-index,Other Topics,Patterns & OO Design...