[JBoss-user] [Persistence & CMP/JBoss] - Re: Foreign key as a Primary Key

2004-04-01 Thread thepriz
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

[JBoss-user] [Persistence & CMP/JBoss] - Re: Foreign key as a Primary Key

2004-03-29 Thread loubyansky
This is done by mapping foreign key fields to primary key columns.
Your example is incorrect as it declares CMR fields as primary keys. Only CMP fields 
can be primary keys.

http://www.jboss.org/index.html?module=bb&op=viewtopic&p=3827846#3827846";>View 
the original post

http://www.jboss.org/index.html?module=bb&op=posting&mode=reply&p=3827846>Reply 
to the post


---
This SF.Net email is sponsored by: IBM Linux Tutorials
Free Linux tutorial presented by Daniel Robbins, President and CEO of
GenToo technologies. Learn everything from fundamentals to system
administration.http://ads.osdn.com/?ad_id=1470&alloc_id=3638&op=click
___
JBoss-user mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-user