Oops, totally forgot that two of your PK attributes are FKs as well. I don't think you can do this with EJBs *if* you also want to use CM-relationships, but I'm not 100% sure. Again, I'd recommend going the single-column surrogate key route. BTW, surrogate key just means that the key's value itself is meaningless with regard to the data. While "Bob Jones" might end up with user_id 37412, he could just as equivalently had user_id 83723.
One main reason to do this is that by relating entities via surrogate keys, you never have to worry about the key changing. If instead you had used email address, then you need to deal with him changing his address and propagating it to all the related entities. As well, using something like number(10)/Integer makes dealing with it in the database and Java code really easy and the same across all entities. David Harkness Sony Pictures Digital Networks (310) 482-4756 -----Original Message----- From: Cristian Rossel Moraga [mailto:[EMAIL PROTECTED] Sent: Friday, August 01, 2003 12:27 PM To: [EMAIL PROTECTED] Cc: Jorge Galindo Fulgeri; [EMAIL PROTECTED]; [EMAIL PROTECTED] Subject: RE: [Xdoclet-user] Primary Key composed by Foreing Key On vie, 2003-08-01 at 11:22, Cristian Rossel Moraga wrote: > Hi David! > > Help me, please... > > How can you with xdoclet declare in a ENTITY BEAN CMP (WORKER) in a PK I'm sorry... How can you with xdoclet declare in a ENTITY BEAN CMP (HAVE_INCOME) in a PK > (primary key) composed by three attribute, and two of these are FK > (foreing key)? > > We use postgreSql 7.3.3, JBOSS 3.07, XDOCLET, ECLIPSE + LOMBOZ. > > Next we introduce other diagram for explicating our problem: > > +-------------+ +-----------------------------------+ > |INCOME |1 *|HAVE_INCOME | > +-------------+------+-----------------------------------| > |codeIncome PK| |date PK | > |name | |codeIncome PK,FK(references INCOME)| > +-------------+ |codeWorker PK,FK(references WORKER)| > |valor | > +-----------------------------------+ > *| > | > | > 1| > +-------------+ > |WORKER | > +-------------| > |codeWorker PK| > |nameWorker | > +-------------+ > > INCOME = INGRESOS. > HAVE_INCOME = TIENE_INGRESOS. > WORKER = TRABAJADOR. > code = codigo. > > > +----------------------+ > |Income | > +----------------------+ > |PK | | > |codeIncome|nameIncome | > +----------+-----------| > |01 |salary | > |02 |bonus | > |03 |extra_hours| > +----------------------+ > > +------------------------+ > |Worker | > +------------------------+ > |PK | | > |codeWorker|nameWorker | > +----------+-------------| > |W1 |John Doe | > |W2 |William Smith| > +------------------------+ > > +--------------------------------------+ > |HAVE_INCOME | > +--------------------------------------+ > |PK |PK, FK |PK, FK | | > |date |codeIncome|codeWorker|valor| > +----------+----------+----------+-----| > |03/01/2003|01 |W1 |1000 | > |05/01/2003|02 |W1 |0500 | > |08/01/2003|02 |W1 |0300 | > |08/01/2003|03 |W1 |0500 | > |04/01/2003|01 |W2 |1000 | > |05/01/2003|02 |W2 |1500 | > |05/01/2003|03 |W2 |0200 | > +--------------------------------------+ > > > > We have developed the following code, but at the moment for making > > deploy in Jboss, this throw one exception: (Nostros hemos > > desarrollado el siguiente c�digo, pero en el momento de realizar el > > montaje en jboss, este lanza la siguiente Exception) > > > > "attribute "icodigoestudiante" duplicated > > > > The code of the InscriptionEJB is: > > > > > > package leufu; > > > > import javax.ejb.EntityBean; > > > > /** > > * @ejb.bean name="Inscripcion" > > * local-jndi-name="InscripcionBean" > > * type="CMP" > > * cmp-version="2.x" > > * view-type="local" > > * schema="Inscripcion" > > * > > * @ejb.persistence > > * table-name="inscripcion" > > * > > * @ejb.finder > > * query="SELECT OBJECT(a) FROM Inscripcion as a" > > * signature="java.util.Collection findAll()" > > * > > * @jboss.create-table true > > * > > **/ > > > > public abstract class InscripcionBean implements EntityBean { > > > > /** > > * > > * @ejb.create-method > > */ > > public InscripcionPK ejbCreate(String codigo, EstudianteLocal e, CursoLocal c) > > throws javax.ejb.CreateException { > > setIMatricula(codigo); > > return new InscripcionPK(codigo,e,c); > > } > > > > /** > > * The container invokes this method immediately after it calls > > ejbCreate. > > * > > */ > > public void ejbPostCreate(String codigo, EstudianteLocal e, CursoLocal c) throws > > javax.ejb.CreateException { > > setICodigoEstudiante(e); > > setICodigoCurso(c); > > } > > > > /** > > * > > * @ejb.persistent-field > > * @ejb.pk-field > > * @ejb.persistence > > * @jboss.column-name imatricula > > * @ejb.interface-method > > */ > > public abstract java.lang.String getIMatricula(); > > > > /** > > * @ejb.interface-method > > */ > > public abstract void setIMatricula(java.lang.String IMatricula); > > > > /** > > * > > * > > [EMAIL PROTECTED] > > [EMAIL PROTECTED] > > [EMAIL PROTECTED] nce > > [EMAIL PROTECTED] icodigoestudiante > > [EMAIL PROTECTED] > > * > > > > /* para las relaciones > > * > > [EMAIL PROTECTED] name="estudiante-inscripcion" > > *role-name="inscripcion-estudiante" > > *target-ejb="Estudiante" > > *target-role-name=" " > > *target-multiple="yes" > > * > > [EMAIL PROTECTED] related-pk-field="eCodigo" > > *fk-column="icodigoestudiante" > > *fk-constraint="true" > > **/ > > > > public abstract leufu.EstudianteLocal getICodigoEstudiante(); > > > > /** > > * > > * @ejb.interface-method > > */ > > public abstract void setICodigoEstudiante(leufu.EstudianteLocal ICodigoEstudiante); > > > > /** > > * > > * @ejb.persistent-field > > * @ejb.pk-field > > * @ejb.persistence > > * @jboss.colum-name icodigocurso > > * @ejb.interface-method > > > > * para las relaciones > > * @ejb.relation name="curso-inscripcion" > > * role-name="inscripcion-curso" > > * target-ejb="Curso" > > * target-role-name=" " > > * target-multiple="yes" > > * > > [EMAIL PROTECTED] related-pk-field="cCodigo" *fk-column="icodigocurso" > > *fk-constraint="true" > > * > > * > > * > > */ > > public abstract leufu.CursoLocal getICodigoCurso(); > > > > /** > > * > > * @ejb.interface-method > > */ > > public abstract void setICodigoCurso(leufu.CursoLocal ICodigoCurso); > > > > } > > > Thanks... > > > Cristian Rossel Moraga > CEO Leufu Ingenieria y Negocios Ltda. > Lebu, Chile, 56-41-511655. > ------------------------------------------------------- This SF.Net email sponsored by: Free pre-built ASP.NET sites including Data Reports, E-commerce, Portals, and Forums are available now. Download today and enter to win an XBOX or Visual Studio .NET. http://aspnet.click-url.com/go/psa00100003ave/direct;at.aspnet_072303_01/01 _______________________________________________ xdoclet-user mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/xdoclet-user ------------------------------------------------------- This SF.Net email sponsored by: Free pre-built ASP.NET sites including Data Reports, E-commerce, Portals, and Forums are available now. Download today and enter to win an XBOX or Visual Studio .NET. http://aspnet.click-url.com/go/psa00100003ave/direct;at.aspnet_072303_01/01 _______________________________________________ xdoclet-user mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/xdoclet-user
