loosing foreign keys
shogun Sep 25, 2002 7:52 AMHi,
I have the problem, that a foreign key is overwritten automatically, when I create a new Instance. Following scenario:
ContentBean 1 ----> 1 RevisionBean
RevisionBean 1 ----> 1 UserBean (creator)
RevisionBean 1 ----> 1 UserBean (modifier)
The ContentBean creates initially one RevisionBean. The Revision gets an input Parameter UserLocal, which it sets to the creator and modifier.
After I create the second Content with the same user, the first revision has no foreign key to the referenced user. The key automatically disappears.
In the JBoss log I saw to updates to the revision table after the creation of the ContentBean. Why there are two updates? I afraid, the first (or second) overwrites the foreign key.
The relation from the revision to the User is discribed with xdoclet (1.2). Using mysql 3.23.52 and JBoss 3.0.2.
/**
* uni-directional
*
* Returns the related Modifier
*
* @return the related de.juwimm.interfaces.UserLocal
* @ejb.interface-method
* view-type="local"
* @ejb.relation
* name="revision-modifier"
* role-name="one-revision-has-one-modifier"
* target-ejb="User"
* target-role-name="one-modifier-belogs-to-one-revision"
* target-multiple="no"
*
* @weblogic.column-map
* foreign-key-column="modifier_id_fk"
* @jboss.relation
* fk-constraint="false"
* fk-column="modifier_id_fk"
* related-pk-field="userNameId"
*/
public abstract de.juwimm.cms.interfaces.UserLocal getModifier();
/**
* Sets the modifier
*
* @param de.juwimm.cms.interfaces.UserLocal modifier
* @ejb.interface-method view-type="local"
*/
public abstract void setModifier(de.juwimm.cms.interfaces.UserLocal modifier);
/**
* uni-directional
*
* Returns the related creator
*
* @return the related de.juwimm.interfaces.UserLocal
* @ejb.interface-method
* view-type="local"
* @ejb.relation
* name="revision-creator"
* role-name="one-revision-has-one-creator"
* target-ejb="User"
* target-role-name="one-creator-belogs-to-one-revision"
* target-multiple="no"
*
* @weblogic.column-map
* foreign-key-column="creator_id_fk"
* @jboss.relation
* fk-column="creator_id_fk"
* related-pk-field="userNameId"
*/
public abstract de.juwimm.cms.interfaces.UserLocal getCreator();
/**
* Sets the creator
*
* @param de.juwimm.cms.interfaces.UserLocal creator
* @ejb.interface-method view-type="local"
*/
public abstract void setCreator(de.juwimm.cms.interfaces.UserLocal creator);
The Revision is created like this:
/**
* The container invokes thos method immediately after it calls ejbCreate.
*
* @param versionId the versionId value
* @param text the text value
* @param revision mandatory CMR field
*/
public void ejbPostCreate( java.lang.String text, de.juwimm.cms.interfaces.UserLocal creator ) throws javax.ejb.CreateException {
// Set CMR fields
try
{
setRevision(RevisionUtil.getLocalHome().create(creator));
}
catch (Exception ex)
{
throw new javax.ejb.CreateException(ex.getMessage());
}
}
Regards,
Dirk