For more info:
CREATE TABLE Communication(
communicationId INT NOT NULL,
PRIMARY KEY (communicationId));
CREATE TABLE BusinessUnit(
businessUnitId INT NOT NULL,
name VARCHAR(255),
type VARCHAR(255),
description VARCHAR(255),
communicationId INT, <- foreign key
addressId INT,
parentId INT,
PRIMARY KEY (businessUnitId));
-----
public abstract class BusinessUnitBean implements EntityBean {
...
// business method
public void setCommunicationId(int communicationId) throws FinderException {
try { setCommunication(getCommunicationLocalHome().findByPrimaryKey(new Integer(communicationId))); }
catch (NamingException ne) { throw new FinderException(ne.toString()); }
}
}
^^
take an example:
businessUnitId = 5
set communicationId from 3 to 6
If I'm in setCommunicationId(), BusinessUnitBean must hold a row, i.e. 5 with communicationId=3. I now call setCommunicationId(6) from a facade bean
-----
# tail -f /var/jboss-3.0.0beta/log/server.log | egrep 'SQL|Set'
2002-03-04 01:43:41,722 DEBUG [org.jboss.ejb.plugins.cmp.jdbc.JDBCFindByPrimaryKeyQuery.BusinessUnit.findByPrimaryKey] Executing SQL: SELECT businessUnitId FROM BusinessUnit WHERE businessUnitId=?
2002-03-04 01:43:41,722 DEBUG [org.jboss.ejb.plugins.cmp.jdbc.JDBCFindByPrimaryKeyQuery.BusinessUnit.findByPrimaryKey] Set parameter: index=1, jdbcType=INTEGER, value=3
+----------------+
| businessUnitId |
+----------------+
| 3 |
+----------------+
2002-03-04 01:43:41,726 DEBUG [org.jboss.ejb.plugins.cmp.jdbc.JDBCLoadEntityCommand.BusinessUnit] Executing SQL: SELECT businessUnitId,name, type, description, parentId, addressId, communicationId FROM BusinessUnit WHERE (businessUnitId=?) OR (businessUnitId=?)
2002-03-04 01:43:41,726 DEBUG [org.jboss.ejb.plugins.cmp.jdbc.bridge.JDBCCMP2xFieldBridge.BusinessUnit.businessUnitId] Set parameter: index=1, jdbcType=INTEGER, value=3
2002-03-04 01:43:41,726 DEBUG [org.jboss.ejb.plugins.cmp.jdbc.bridge.JDBCCMP2xFieldBridge.BusinessUnit.businessUnitId] Set parameter: index=2, jdbcType=INTEGER, value=5
+----------------+-------------------+-------------+------------------+----------+-----------+-----------------+
| businessUnitId | name | type | description | parentId | addressId | communicationId |
+----------------+-------------------+-------------+------------------+----------+-----------+-----------------+
| 3 | Entersys | limited | Entersys Limited | 0 | 4 | 3 | <- it'll change to 6
| 5 | Entersys Software | corporation | Entersys Limited | 0 | 5 | 6 |
+----------------+-------------------+-------------+------------------+----------+-----------+-----------------+
2002-03-04 01:43:41,754 DEBUG [org.jboss.ejb.plugins.cmp.jdbc.JDBCFindByPrimaryKeyQuery.Communication.findByPrimaryKey] Executing SQL: SELECT communicationId FROM Communication WHERE communicationId=?
2002-03-04 01:43:41,754 DEBUG [org.jboss.ejb.plugins.cmp.jdbc.JDBCFindByPrimaryKeyQuery.Communication.findByPrimaryKey] Set parameter: index=1, jdbcType=INTEGER, value=6
+-----------------+
| communicationId |
+-----------------+
| 6 |
+-----------------+
2002-03-04 01:43:41,758 DEBUG [org.jboss.ejb.plugins.cmp.jdbc.JDBCLoadRelationCommand.Communication] Executing SQL: SELECT businessUnitId FROM BusinessUnit WHERE (communicationId=?)
2002-03-04 01:43:41,758 DEBUG [org.jboss.ejb.plugins.cmp.jdbc.bridge.JDBCCMP2xFieldBridge.BusinessUnit.communicationId] Set parameter: index=1, jdbcType=INTEGER, value=3
2002-03-04 01:43:41,775 DEBUG [org.jboss.ejb.plugins.cmp.jdbc.JDBCStoreEntityCommand.BusinessUnit] Executing SQL: UPDATE BusinessUnit SET communicationId=? WHERE businessUnitId=?
2002-03-04 01:43:41,775 DEBUG [org.jboss.ejb.plugins.cmp.jdbc.bridge.JDBCCMP2xFieldBridge.BusinessUnit.communicationId] Set parameter: index=1, jdbcType=INTEGER, value=6
2002-03-04 01:43:41,775 DEBUG [org.jboss.ejb.plugins.cmp.jdbc.bridge.JDBCCMP2xFieldBridge.BusinessUnit.businessUnitId] Set parameter: index=2, jdbcType=INTEGER, value=3
Seems ok, but there'r expections going on (pls compare the time with above)
# cat /var/jboss-3.0.0beta/log/server.log | egrep '43:.*ERROR'
2002-03-04 01:43:41,762 ERROR [org.jboss.ejb.plugins.LogInterceptor] TransactionRolledbackException, causedBy:
2002-03-04 01:43:41,768 ERROR [org.jboss.ejb.plugins.LogInterceptor] TransactionRolledbackException, causedBy:
2002-03-04 01:43:41,777 ERROR [org.jboss.invocation.jrmp.server.JRMPInvoker] operation failed
To get the detail about the error, I get:
2002-03-04 01:43:41,762 ERROR [org.jboss.ejb.plugins.LogInterceptor] TransactionRolledbackException, causedBy:
java.lang.IllegalStateException: A CMR field cannot be set or added to a relationship in ejbCreate; this should be done in the ejbP$
at org.jboss.ejb.plugins.cmp.jdbc.bridge.JDBCCMRFieldBridge.addRelation(JDBCCMRFieldBridge.java:749)
at org.jboss.ejb.plugins.cmp.jdbc.JDBCRelationInterceptor.invoke(JDBCRelationInterceptor.java:146)
at org.jboss.ejb.plugins.EntitySynchronizationInterceptor.invoke(EntitySynchronizationInterceptor.java:296)
at org.jboss.ejb.plugins.EntityInstanceInterceptor.invoke(EntityInstanceInterceptor.java:189)
at org.jboss.ejb.plugins.EntityLockInterceptor.invoke(EntityLockInterceptor.java:108)
at org.jboss.ejb.plugins.AbstractTxInterceptor.invokeNext(AbstractTxInterceptor.java:96)
at org.jboss.ejb.plugins.TxInterceptorCMT.runWithTransactions(TxInterceptorCMT.java:167)
at org.jboss.ejb.plugins.TxInterceptorCMT.invoke(TxInterceptorCMT.java:61)
at org.jboss.ejb.plugins.SecurityInterceptor.invoke(SecurityInterceptor.java:127)
at org.jboss.ejb.plugins.LogInterceptor.invoke(LogInterceptor.java:166)
at org.jboss.ejb.EntityContainer.invoke(EntityContainer.java:475)
at org.jboss.ejb.plugins.cmp.jdbc.bridge.JDBCCMRFieldBridge.invokeAddRelation(JDBCCMRFieldBridge.java:682)
at org.jboss.ejb.plugins.cmp.jdbc.bridge.JDBCCMRFieldBridge.createRelationLinks(JDBCCMRFieldBridge.java:609)
at org.jboss.ejb.plugins.cmp.jdbc.bridge.JDBCCMRFieldBridge.setInstanceValue(JDBCCMRFieldBridge.java:573)
at org.jboss.ejb.plugins.cmp.jdbc.bridge.JDBCCMRFieldBridge.setValue(JDBCCMRFieldBridge.java:511)
at org.jboss.ejb.plugins.cmp.bridge.EntityBridgeInvocationHandler.invoke(EntityBridgeInvocationHandler.java:115)
at org.jboss.proxy.compiler.ProxyCompiler$Runtime.invoke(ProxyCompiler.java:89)
at esb.ejb.BusinessUnitCMP$Proxy.setCommunication(Unknown Source)