-
1. Re: Compound PK problem
beal91 Apr 1, 2004 8:04 AM (in response to javri28)I would have a create() method that accepts as parameters the three entities that comprise the three-way relationship:
public SasAssignmentPK ejbCreate(SampTableLocal table,
ProductGroupLocal prodGroup,
SasLocal sas) throws javax.ejb.CreateException {
setSampTableId(table.getTableId());
setProductGroupId(prodGroup.getGroupId());
setSasId(sas.getSasId());
return null;
}
I would also define equivalent CMR fields (taking care to map them to the same database columns) for each of these relations, and set the relationship values in a postCreate() method:
public void ejbPostCreate(SampTableLocal table,
ProductGroupLocal prodGroup,
SasLocal sas) {
setTable(table);
setProductGroup(prodGroup);
setSas(sas);
}
-- Jeff Beal -
2. Re: Compound PK problem
thepriz Apr 1, 2004 2:29 PM (in response to javri28)Why do you set the relations in the post create if you have already set the ids in the create?
-
3. Re: Compound PK problem
beal91 Apr 1, 2004 2:59 PM (in response to javri28)I like to set the relationship field in the code rather than "counting on" the bean deployer to correctly map the two EJB fields to the same column in the database. It's probably not necessary, but it does make the EJB less sensitive to a particular deployment. If I ever decide to deploy my beans in a different application server or to a different database, I don't have to map the database fields in order for the code to work.
-
4. Re: Compound PK problem
javri28 Apr 2, 2004 1:05 AM (in response to javri28)This is what i had in my bean:
** @ejb.persistence column-name = "ST_ID"
* @ejb.interface-method view-type = "both"
* @return
*/
abstract public Integer getSampTableId();
/** @ejb.interface-method view-type = "both" */
abstract public void setSampTableId(Integer sampTableId);
/** @ejb.persistence column-name = "PG_ID"
* @ejb.interface-method view-type = "both"
* @return
*/
abstract public Integer getProductGroupId();
/** @ejb.interface-method view-type = "both" */
abstract public void setProductGroupId(Integer productGroupId);
/** @ejb.persistence column-name = "SAS_ID"
* @ejb.interface-method view-type = "both"
* @return
*/
abstract public Integer getSasId();
/** @ejb.interface-method view-type = "both" */
abstract public void setSasId(Integer sasId);
public SasAssignmentPK ejbCreate(SampTableLocal sampTable, ProductGroupLocal productGroup, SampAttributeSetLocal sas) throws CreateException {
setProductGroupId(productGroup.getId());
setSasId(sas.getId());
setSampTableId(sampTable.getId());
return null;
}
public void ejbPostCreate(SampTableLocal sampTable, ProductGroupLocal productGroup, SampAttributeSetLocal sas) throws CreateException {
/*
setSampTable(sampTable);
setProductGroup(productGroup);
setSampAttributeSet(sas);
*/
}
And the exception was:
javax.ejb.TransactionRolledbackLocalException: Internal error setting instance field sampTableId; CausedByException is:
de.keywork.moc.sampling.pk.SasAssignmentPK; CausedByException is:
Internal error setting instance field sampTableId; CausedByException is:
de.keywork.moc.sampling.pk.SasAssignmentPK
at org.jboss.ejb.plugins.AbstractTxInterceptor.invokeNext(AbstractTxInterceptor.java:204)
... bla-bla-bla
Any ides after reading this long story? :-) -
5. Re: Compound PK problem
aloubyansky Apr 3, 2004 5:59 AM (in response to javri28)I guess this is because you don't have a no-arg constructor for the PK class.