First, I'd recommend against this design. This may be me getting stuck doing one thing for far too long, but ever since I first began designing SQL databases (1989) I've always found that using a single-column surrogate key ends up being much easier. We tend to do what we already know, but I haven't seen any compelling reason to do it any differently.
Therefore, I'd create a new column in HAVE_INCOME: codeHaveIncome (I always use "id" for the PK in every table with FKs like "user_id" and "worker_id", but that's me). If you go this route, then the HaveIncome entity bean is just like all other entity beans. However, if you decide to stick with this design (or you may have to), you'll need to create a primary-key class to hold the three attributes that make it up. This is a requirement of the EJB spec -- each entity bean has a single PK *attribute*, even if that attribute is composed of multiple columns. I haven't done this before, but it seems pretty simple. The PK class is a simple POJO with get/set accessors. You'll need to use different XDoclet tags than your other entities like pk-class and such. They're in the docs. Let me know if I can assist you further. Good luck! David Harkness Sony Pictures Digital Networks (310) 482-4756 -----Original Message----- From: Cristian Rossel Moraga [mailto:[EMAIL PROTECTED] Sent: Friday, August 01, 2003 8:22 AM To: [EMAIL PROTECTED] Cc: [EMAIL PROTECTED]; [EMAIL PROTECTED]; [EMAIL PROTECTED]; [EMAIL PROTECTED]; [EMAIL PROTECTED]; Ximena Agurto Contreras; Jorge Galindo Fulgeri; Julio Eyzaguirre; Daniel S�ez Subject: RE: [Xdoclet-user] Primary Key composed by Foreing Key Hi David! Help me, please... How can you with xdoclet declare in a ENTITY BEAN CMP (WORKER) 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
