Compound PK DeploymentException
ebende Mar 9, 2004 3:51 AMHi everybody,
I have question concerning compound primary keys in CMP2.0 EJBs.
I've got a deployment error: "Generation only supported with single PK field" from Jboss 3.2.2 (See below).
What do I do wrong?
Do I need to configure someting in JBoss in addition?
My codes and xml-pieces for a vey simple test-bean ("A") with corresponding DB table ("a") are listed below.
I appreciate any help.
Thanks,
Evert Bende
PS:
The PK-class was generated by Borland JBuilderX.
My table is stored in a MySQL database.
None of the pks in table "a" are auto-incremented.
I also tried it with a create statement with a single argument, like ejbCreate(APK apk){...}, but this didn't work out either.
//////////////////////////////////////////
Deployment Error from JBOSS-3.2.2
//////////////////////////////////////////
2004-03-04 11:37:08,501 ERROR [org.jboss.ejb.EntityContainer] Starting failed
org.jboss.deployment.DeploymentException: Generation only supported with single PK field
at org.jboss.ejb.plugins.cmp.jdbc.JDBCAbstractCreateCommand.getGeneratedPKField(JDBCAbstractCreateCommand.java:171)
at org.jboss.ejb.plugins.cmp.jdbc.JDBCIdentityColumnCreateCommand.initGeneratedFields(JDBCIdentityColumnCreateCommand.java:46)
at org.jboss.ejb.plugins.cmp.jdbc.JDBCAbstractCreateCommand.init(JDBCAbstractCreateCommand.java:91)
at org.jboss.ejb.plugins.cmp.jdbc.keygen.JDBCMySQLCreateCommand.init(JDBCMySQLCreateCommand.java:40)
at org.jboss.ejb.plugins.cmp.jdbc.JDBCCommandFactory.createCreateEntityCommand(JDBCCommandFactory.java:128)
at org.jboss.ejb.plugins.cmp.jdbc.JDBCStoreManager.startStoreManager(JDBCStoreManager.java:427)
at org.jboss.ejb.plugins.cmp.jdbc.JDBCStoreManager.start(JDBCStoreManager.java:351)
at org.jboss.ejb.plugins.CMPPersistenceManager.start(CMPPersistenceManager.java:152)
at org.jboss.ejb.EntityContainer.startService(EntityContainer.java:343)
at org.jboss.system.ServiceMBeanSupport.start(ServiceMBeanSupport.java:192)
at sun.reflect.GeneratedMethodAccessor133.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
//////////////////////////////////////////
ABean
//////////////////////////////////////////
package com.wattabout.wattsbest.ejb.cmp;
import javax.ejb.EntityBean;
import javax.ejb.EntityContext;
import javax.ejb.CreateException;
import javax.ejb.RemoveException;
public abstract class ABean
implements EntityBean {
EntityContext entityContext;
public APK ejbCreate(Integer apk1, Integer apk2) throws CreateException {
setApk1(apk1);
setApk2(apk2);
return null;
}
public void ejbPostCreate(Integer apk1, Integer apk2) throws CreateException { }
public void ejbRemove() throws RemoveException { }
public abstract void setAfld(String afld);
public abstract void setApk1(Integer apk1);
public abstract void setApk2(Integer apk2);
public abstract String getAfld();
public abstract Integer getApk1();
public abstract Integer getApk2();
public void ejbLoad() { }
public void ejbStore() { }
public void ejbActivate() { }
public void ejbPassivate() { }
public void setEntityContext(EntityContext entityContext) { this.entityContext = entityContext; }
public void unsetEntityContext() { this.entityContext = null; }
}
//////////////////////////////////////////
A
//////////////////////////////////////////
package com.wattabout.wattsbest.ejb.cmp;
import javax.ejb.EJBLocalObject;
public interface A extends EJBLocalObject {
public void setAfld(String afld);
public String getAfld();
public Integer getApk1();
public Integer getApk2();
}
//////////////////////////////////////////
AHome
//////////////////////////////////////////
package com.wattabout.wattsbest.ejb.cmp;
import javax.ejb.EJBLocalHome;
import javax.ejb.CreateException;
import javax.ejb.FinderException;
public interface AHome extends EJBLocalHome {
public A create(Integer apk1, Integer apk2) throws CreateException;
public A findByPrimaryKey(APK pk) throws FinderException;
}
//////////////////////////////////////////
APK
//////////////////////////////////////////
package com.wattabout.wattsbest.ejb.cmp;
import java.io.Serializable;
public class APK
implements Serializable {
public Integer apk1;
public Integer apk2;
public APK() {
}
public APK(Integer apk1, Integer apk2) {
this.apk1 = apk1;
this.apk2 = apk2;
}
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (! (obj instanceof APK)) {
return false;
}
APK that = (APK) obj;
if (! (that.apk1 == null ? this.apk1 == null : that.apk1.equals(this.apk1))) {
return false;
}
if (! (that.apk2 == null ? this.apk2 == null : that.apk2.equals(this.apk2))) {
return false;
}
return true;
}
public int hashCode() {
int result = 17;
result = 37 * result + this.apk1.hashCode();
result = 37 * result + this.apk2.hashCode();
return result;
}
}
//////////////////////////////////////////
ejb-jar.xml
//////////////////////////////////////////
<display-name>A</display-name>
<ejb-name>A</ejb-name>
<local-home>com.wattabout.wattsbest.ejb.cmp.AHome</local-home>
com.wattabout.wattsbest.ejb.cmp.A
<ejb-class>com.wattabout.wattsbest.ejb.cmp.ABean</ejb-class>
<persistence-type>Container</persistence-type>
<prim-key-class>com.wattabout.wattsbest.ejb.cmp.APK</prim-key-class>
False
<cmp-version>2.x</cmp-version>
<abstract-schema-name>A</abstract-schema-name>
<cmp-field>
<field-name>afld</field-name>
</cmp-field>
<cmp-field>
<field-name>apk1</field-name>
</cmp-field>
<cmp-field>
<field-name>apk2</field-name>
</cmp-field>
//////////////////////////////////////////
jbosscmp-jdbc.xml
//////////////////////////////////////////
<ejb-name>A</ejb-name>
<table-name>a</table-name>
<cmp-field>
<field-name>afld</field-name>
<column-name>afld</column-name>
</cmp-field>
<cmp-field>
<field-name>apk1</field-name>
<column-name>apk1</column-name>
</cmp-field>
<cmp-field>
<field-name>apk2</field-name>
<column-name>apk2</column-name>
</cmp-field>