I've gotten EJB->dep obj working for 1-to-1 and
I've gotten EJB->EJB 1-to-1 and 1-to-many working.
But for the life of me, I cannot get EJB->dep obj
working for 1-to-many.
The object model is:
EdiFile(EJB) ---- 1 to N ----- EdiEnvelope (DO)
This is a unidirectional relationship. I think
someone has been trying bi-directional with no
luck.
The problem manifests itself in two ways. First,
Orion throws an error when it tries to compiles
the stubs/skeletons:
class EdiEnvelope_Dependent0 is an abstract class.
It can't be instantiated.
(well this is obvious; dependent objects are supposed
to be abstract).
Second, the database table for my EJB doesn't contain
_any_ reference to the dependent object. BTW, the
table for the dependent object looks fine.
Thanks for any help,
-tim
Here is my dependent object:
------------------------------------------------------
package com.tfc.ejb;
import java.rmi.RemoteException;
import javax.ejb.RemoveException;
import java.util.Date;
import java.util.Collection;
import java.util.Iterator;
public abstract class EdiEnvelope implements java.io.Serializable
{
public abstract void setSenderIdQualifier(String s) throws
RemoteException;
public abstract void setSenderId(String s) throws RemoteException;
public abstract void setReceiverIdQualifier(String s) throws
RemoteException;
public abstract void setReceiverId(String s) throws RemoteException;
public abstract void setDate(Date d) throws RemoteException;
public abstract void setVersion(String s) throws RemoteException;
public abstract void setControlNumber(long l) throws RemoteException;
public abstract void setAck(boolean b) throws RemoteException;
public abstract void setNumberOfGroups(int i) throws RemoteException;
public abstract void setTransactionSets(Collection c) throws
RemoteException;
public abstract void setId(String s) throws RemoteException;
public abstract String getSenderIdQualifier() throws RemoteException;
public abstract String getSenderId() throws RemoteException;
public abstract String getReceiverIdQualifier() throws RemoteException;
public abstract String getReceiverId() throws RemoteException;
public abstract Date getDate() throws RemoteException;
public abstract String getVersion() throws RemoteException;
public abstract long getControlNumber() throws RemoteException;
public abstract boolean getAck() throws RemoteException;
public abstract int getNumberOfGroups() throws RemoteException;
public abstract Collection getTransactionSets() throws RemoteException;
public abstract String getId() throws RemoteException;
public String ejbCreateEdiEnvelope() throws RemoteException
{
this.setId( (new java.rmi.server.UID()).toString() );
return null;
}
public void ejbPostCreateEdiEnvelope() { }
public abstract EdiEnvelope deepCopy();
} // end EdiEnvelope
----------------------------------------------------------
Here is my EJB:
----------------------------------------------------------
package com.tfc.ejb;
import javax.ejb.EntityBean;
import javax.ejb.CreateException;
import javax.ejb.RemoveException;
import java.rmi.RemoteException;
import javax.ejb.EntityContext;
import java.util.Date;
import java.util.Iterator;
import java.util.Collection;
public abstract class EdiFileEJB implements EntityBean
{
private EntityContext ec;
// accessors
public void setEntityContext(EntityContext ec) { this.ec = ec; }
public void unsetEntityContext() { ec = null; }
public abstract void setFilename(String s);
public abstract void setDateDownloaded(Date d);
public abstract void setEnvelopes(Collection c);
public abstract void setId(String s);
public abstract String getFilename();
public abstract Date getDateDownloaded();
public abstract Collection getEnvelopes();
public abstract String getId();
public long getNumberOfEnvelopes()
{
Collection c = this.getEnvelopes();
return c.size();
}
public long getEnvelopeControlNumber(int index) throws RemoteException
{
long controlNumber = 0;
Collection c = this.getEnvelopes();
try {
EdiEnvelope[] ea = (EdiEnvelope[])c.toArray();
EdiEnvelope e = ea[index];
controlNumber = e.getControlNumber();
} catch (Exception ex) {
throw new RemoteException("index out of bounds");
}
return controlNumber;
}
public void addEnvelope(String senderIdQualifier,
String senderId,
String receiverIdQualifier,
String receiverId,
Date date,
String version,
long controlNumber,
boolean ack) throws RemoteException,
CreateException
{
EdiEnvelope e = this.createEdiEnvelope();
e.setSenderIdQualifier(senderIdQualifier);
e.setSenderId(senderId);
e.setReceiverIdQualifier(receiverIdQualifier);
e.setReceiverId(receiverId);
e.setDate(date);
e.setVersion(version);
e.setControlNumber(controlNumber);
e.setAck(ack);
this.getEnvelopes().add(e);
}
public abstract EdiEnvelope createEdiEnvelope() throws CreateException;
public String ejbCreate()
{
this.setId( (new java.rmi.server.UID()).toString() );
return null;
}
public void ejbPostCreate() { }
public void ejbActivate() { }
public void ejbPassivate() { }
public void ejbLoad() { }
public void ejbStore() { }
public void ejbRemove() { }
} // end EdiFileEJB
---------------------------------------------------
and here are the relevent parts of ejb-jar.xml:
----------------------------------------------------
...
<entity>
<cmp-version>2.x</cmp-version>
<description>EDI file</description>
<ejb-name>EdiFileEJB</ejb-name>
<home>com.tfc.ejb.EdiFileHome</home>
<remote>com.tfc.ejb.EdiFile</remote>
<ejb-class>com.tfc.ejb.EdiFileEJB</ejb-class>
<persistence-type>Container</persistence-type>
<reentrant>False</reentrant>
<cmp-field>
<field-name>filename</field-name>
</cmp-field>
<cmp-field>
<field-name>dateDownloaded</field-name>
</cmp-field>
<cmp-field>
<field-name>envelopes</field-name>
</cmp-field>
<cmp-field>
<field-name>id</field-name>
</cmp-field>
<primkey-field>id</primkey-field>
<prim-key-class>java.lang.String</prim-key-class>
</entity>
...
<dependent>
<dependent-name>EdiEnvelope</dependent-name>
<dependent-class>com.tfc.ejb.EdiEnvelope</dependent-class>
<cmp-field>
<field-name>senderIdQualifier</field-name>
</cmp-field>
<cmp-field>
<field-name>senderId</field-name>
</cmp-field>
<cmp-field>
<field-name>receiverIdQualifier</field-name>
</cmp-field>
<cmp-field>
<field-name>receiverId</field-name>
</cmp-field>
<cmp-field>
<field-name>date</field-name>
</cmp-field>
<cmp-field>
<field-name>version</field-name>
</cmp-field>
<cmp-field>
<field-name>controlNumber</field-name>
</cmp-field>
<cmp-field>
<field-name>ack</field-name>
</cmp-field>
<cmp-field>
<field-name>transactionSets</field-name>
</cmp-field>
<cmp-field>
<field-name>id</field-name>
</cmp-field>
<prim-key-class>java.lang.String</prim-key-class>
<primkey-field>id</primkey-field>
</dependent>
...
<ejb-relation>
<ejb-relation-name>EdiFile-EdiEnvelopes</ejb-relation-name>
<ejb-relationship-role>
<ejb-relationship-role-name>EdiFile-has-EdiEnvelopes</ejb-relationship-role-
name>
<multiplicity>one</multiplicity>
<role-source>
<ejb-name>EdiFileEJB</ejb-name>
</role-source>
<cmr-field>
<cmr-field-name>envelopes</cmr-field-name>
<cmr-field-type>java.util.Collection</cmr-field-type>
</cmr-field>
</ejb-relationship-role>
<ejb-relationship-role>
<ejb-relationship-role-name>EdiEnvelopes-belongsto-EdiFile</ejb-relationship
-role-name>
<multiplicity>many</multiplicity>
<role-source>
<dependent-name>EdiEnvelope</dependent-name>
</role-source>
<cmr-field>
<cmr-field-name>ediFile</cmr-field-name>
</cmr-field>
</ejb-relationship-role>
</ejb-relation>