Here is a Primary Key related to a Foriegn key relation in a one to one relation.
| /***
| * *
| * JBoss: The OpenSource J2EE WebOS *
| * *
| * Distributable under LGPL license. *
| * See terms of license at gnu.org. *
| * *
| ***/
| package org.jboss.nukes.addons.modules.kingpin.ejb;
|
| import javax.ejb.EntityBean;
| import javax.ejb.CreateException;
| import javax.ejb.EntityContext;
|
| import java.util.Collection;
|
| /**
| * Tape EJB for the kingpin module
| *
| * @author mailto:[EMAIL PROTECTED]">Dennis Przybyla
| * @version $Revision: 1.5 $
| *
| * @ejb.bean
| *name="Tape"
| *displayContent-name="Tape"
| *type="CMP"
| *cmp-version="2.x"
| *view-type="both"
| *jndi-name="nukes/kingpin/Tape"
| *local-jndi-name="nukes/kingpin/TapeLocal"
| *schema="Tape"
| *primkey-field="mediaId"
| *
| * @ejb.transaction
| *type="Required"
| *
| * @ejb.persistence
| *table-name="Tape"
| *
| * @ejb.finder
| *signature="org.jboss.nukes.addons.modules.kingpin.ejb.TapeEJBLocal
findByPrimaryKey(java.lang.Long id)"
| *
| * @jboss.persistence
| *create-table="true"
| *remove-table="false"
| *
| * @jboss.entity-command
| *name="default"
| *
| */
| public abstract class TapeEJB implements EntityBean {
|
| /**
| * @ejb.create-method
| */
| public Long ejbCreate(Long mediaId, String tapeNumber, String tapeType)
| throws CreateException {
|
| setTapeNumber(tapeNumber);
| setTapeType(tapeType);
| System.out.println("record inserted");
| setMediaId(mediaId);
| return null;
| }
|
| public void ejbPostCreate(Long mediaId, String tapeNumber, String tapeType)
| throws CreateException {
| System.out.println("post create done");
| }
|
| /**
| * @ejb.interface-method
| * @ejb.persistence
| *column-name="media_id"
| * @jboss.persistence
| *auto-increment="false"
| */
| public abstract Long getMediaId();
|
| public abstract void setMediaId(Long mediaId);
|
| /**
| * @ejb.interface-method
| * @ejb.relation
| *name="Tape-Media"
| *role-name="Tape-is-a-Media"
| *target-ejb="Media"
| *target-role-name="Media-is-a-Tape"
| *multiplicity="many"
| * @jboss.relation
| *fk-column="media_id"
| *related-pk-field="mediaId"
| * @jboss.target-relation
| *fk-column="media_id"
| *related-pk-field="mediaId"
| */
| public abstract org
| .jboss
| .nukes
| .addons
| .modules
| .kingpin
| .ejb
| .MediaLocal getMedia();
|
| /**
| * @ejb.interface-method
| */
| public abstract void setMedia(
| org.jboss.nukes.addons.modules.kingpin.ejb.MediaLocal media);
|
| /**
| * @ejb.interface-method
| * @ejb.persistence
| *column-name="tape_number"
| */
| public abstract String getTapeNumber();
|
| /**
| * @ejb.interface-method
| * @ejb.persistence
| *column-name="tape_number"
| */
| public abstract void setTapeNumber(String tapeNumber);
|
| /**
| * @ejb.interface-method
| * @ejb.persistence
| *column-name="tape_type"
| */
| public abstract String getTapeType();
|
| /**
| * @ejb.interface-method
| * @ejb.persistence
| *column-name="tape_type"
| */
| public abstract void setTapeType(String tapeType);
|
| // ejb callbacks
|
| public void ejbActivate() {
| }
| public void ejbPassivate() {
| }
| public void ejbRemove() {
| }
| public void setEntityContext(EntityContext entityContext) {
| }
| public void unsetEntityContext() {
| }
| public void ejbLoad() {
| }
| public void ejbStore() {
| }
| }
|
This works fine when media and tape both have the same id numbers in thier tables. In
other words if all ids in the media table match all the ids in the tape table it works
fine. however I also have a ftp table, and a dbExportFile table that are also a
one-to-one relationship with media. when you add an ftp record then add an tape you
get an error. I would expect that the ftp record should have an id of 1 in both the
media and ftp table which i