simplest one-to-one relationships bug
nacho2004 May 18, 2004 6:55 AMHi all!!
I've 2 tables that contain the same primary key (docid)
and both have diferent fileds for a document
One of that has all the basic fields for a document and the other has metadata for the same document.
Obviously the relation is one-to-one
well, the names of the beans are : EDocuments and EDocMetaData
This is the code for EDocuments:
/**
* @ejb.bean name="EDocuments"
* jndi-name="EDocumentsBean"
* type="CMP"
* schema="documents"
* cmp-version="2.x"
* primkey-field="docid"
*
* @ejb.persistence
* table-name="documents"
*
* @ejb.finder
* query="SELECT OBJECT(a) FROM documents as a"
* signature="java.util.Collection findAll()"
**/
/**
* @ejb.interface-method
*
* @ejb.relation
* name="EDocuments-EDocMetaData"
* role-name="EDocuments-has-one-EDocMetadata"
*
* @jboss.relation
* related-pk-field="docid"
* fk-column="docid"
*
*/
public abstract EDocMetaData getEDocMetaData();
/**
* @ejb.interface-method
* view-type="both"
*/
public abstract void setEDocMetaData(EDocMetaData metaData);
and this is for EDocMetaData bean :
/**
* @ejb.bean name="EDocMetaData"
* jndi-name="EDocMetaDataBean"
* type="CMP"
* primkey-field="docid"
* schema="docmetadata"
* cmp-version="2.x"
*
* @ejb.persistence
* table-name="docmetadata"
*
* @ejb.finder
* query="SELECT OBJECT(a) FROM docmetadata as a"
* signature="java.util.Collection findAll()"
*
**/
/**
* @ejb.interface-method
*
* @ejb.relation
* name="EDocuments-EDocMetaData"
* role-name="EDocMetadata-has-one-EDocuments"
* @jboss.relation
* related-pk-field="docid"
* fk-column="docid"
*/
public abstract EDocuments getEDocuments();
public abstract void setEDocuments(EDocuments document);
This is the code for ejb-jar.xml
<!-- Relationships -->
<ejb-relation >
<ejb-relation-name>EDocuments-EDocMetaData</ejb-relation-name>
<ejb-relationship-role >
<ejb-relationship-role-name>EDocuments-has-one-EDocMetadata
</ejb-relationship-role-name>
One
<relationship-role-source >
<ejb-name>EDocuments</ejb-name>
</relationship-role-source>
<cmr-field >
<cmr-field-name>EDocMetaData</cmr-field-name>
</cmr-field>
</ejb-relationship-role>
<ejb-relationship-role >
<ejb-relationship-role-name>EDocMetadata-has-one-EDocuments</ejb-relationship-role-name>
One
<relationship-role-source >
<ejb-name>EDocMetaData</ejb-name>
</relationship-role-source>
<cmr-field >
<cmr-field-name>eocuments</cmr-field-name>
</cmr-field>
</ejb-relationship-role>
</ejb-relation>
and this is for jbosscmp-jdbc
<ejb-relation>
<ejb-relation-name>EDocuments-EDocMetaData</ejb-relation-name>
<foreign-key-mapping/>
<ejb-relationship-role>
<ejb-relationship-role-name>EDocuments-has-one-EDocMetadata</ejb-relationship-role-name>
<key-fields>
<key-field>
<field-name>docid</field-name>
<column-name>docid</column-name>
</key-field>
</key-fields>
</ejb-relationship-role>
<ejb-relationship-role>
<ejb-relationship-role-name>EDocMetadata-has-one-EDocuments</ejb-relationship-role-name>
<key-fields>
<key-field>
<field-name>docid</field-name>
<column-name>docid</column-name>
</key-field>
</key-fields>
</ejb-relationship-role>
</ejb-relation>
Well,
Finally I'm using Lomboz for generate all deploy files and
all the file were generated well and the deploy files were good too.
But when I want to use the client tester like this :
public class DocumentsTest {
private com.Entrieva.Skyline.SessionBeans.SDocumentsHome getHome()
throws NamingException {
return (com.Entrieva.Skyline.SessionBeans.SDocumentsHome) getContext().lookup(
com.Entrieva.Skyline.SessionBeans.SDocumentsHome.JNDI_NAME);
}
private InitialContext getContext() throws NamingException {
Hashtable props = new Hashtable();
props.put(InitialContext.INITIAL_CONTEXT_FACTORY,
"org.jnp.interfaces.NamingContextFactory");
props.put(InitialContext.PROVIDER_URL, "jnp://127.0.0.1:1099");
InitialContext initialContext = new InitialContext(props);
return initialContext;
}
public void testBean() throws CreateException, RemoteException, FinderException {
try {
SDocuments myBean = getHome().create();
Collection col = myBean.getAllDocumentByCategoryId(11);
// get all documents by category
Iterator iter = col.iterator();
while (iter.hasNext()) {
EDocuments element = ((EDocuments) iter.next());
System.out.println("Abstract:" + element.getShortabstract());
EDocMetaData meta = element.getEDocMetaData();}
} catch (NamingException e) {
e.printStackTrace();
}
}
public static void main(String[] args) throws RemoteException, CreateException, FinderException {
DocumentsTest test = new DocumentsTest();
test.testBean();
}
this bugs appear in the console:
java.rmi.ServerException: RemoteException occurred in server thread; nested exception is:
java.rmi.ServerException: RuntimeException; nested exception is:
java.lang.ClassCastException
at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:292)
at sun.rmi.transport.Transport$1.run(Transport.java:148)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.Transport.serviceCall(Transport.java:144)
at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:460)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:701)
at java.lang.Thread.run(Thread.java:536)
at sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(StreamRemoteCall.java:247)
at sun.rmi.transport.StreamRemoteCall.executeCall(StreamRemoteCall.java:223)
at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:133)
at org.jboss.invocation.jrmp.server.JRMPInvoker_Stub.invoke(Unknown Source)
at org.jboss.invocation.jrmp.interfaces.JRMPInvokerProxy.invoke(JRMPInvokerProxy.java:135)
at org.jboss.invocation.InvokerInterceptor.invoke(InvokerInterceptor.java:96)
at org.jboss.proxy.TransactionInterceptor.invoke(TransactionInterceptor.java:46)
at org.jboss.proxy.SecurityInterceptor.invoke(SecurityInterceptor.java:45)
at org.jboss.proxy.ejb.EntityInterceptor.invoke(EntityInterceptor.java:97)
at org.jboss.proxy.ClientContainer.invoke(ClientContainer.java:85)
at $Proxy2.getEDocMetaData(Unknown Source)
at com.neoris.Test.DocumentsTest.testBean(DocumentsTest.java:58)
at com.neoris.Test.DocumentsTest.main(DocumentsTest.java:67)
Thanks in advance any help !!!!!