[jboss-user] [EJB/JBoss] - How to deploy on JBoss a CMP bean that uses a composite PK i

hjoly do-not-reply at jboss.com
Fri May 25 11:25:20 EDT 2007


Hi,
    I'm trying to port a sun tutorial into JBoss 4.0.4.  Some of the CMP beans have a PK class whose fields refer to a composite PK in the corresponding table.

What I don't know is how to specify this in the jbosscmp-jdbc.xml file.  In fact I'm asking if it's even possible to have composite primary keys for CMP beans in JBoss.
If so, how to do it.  Here's my bean, its PK class & its table:

create table PART (
  | 	PART_NUMBER    VARCHAR(15)    NOT NULL,
  | 	REVISION	    NUMERIC(2)	     NOT NULL,
  | 	DESCRIPTION	    VARCHAR(255)  NULL,
  | 	PRIMARY KEY (PART_NUMBER, REVISION),
  | );
  | 
  | public final class PartKey implements java.io.Serializable {
  |     public String partNumber;
  |     public int revision;
  |     public boolean equals(Object otherOb) {...}
  |     public int hashCode() {...}
  |     public String toString() {...}
  | }
  | 
  | /**
  |  * @ejb.bean
  |  *   name=PartBean
  |  *   local-jndi-name="ejb/LocalPart"
  |  *   type="CMP"
  |  *   reentrant="false"
  |  *   cmp-version="2.x"
  |  *   schema="Part"
  |  *   view-type="local"
  |  * 
  |  * @ejb.persistence table-name="PART"
  |  * 
  |  * @ejb.pk class="dataregistry.PartKey"
  |  * 
  |  * @jboss.persistence
  |  *    datasource="java:/SunTutOrderDS" 
  |  *    datasource-mapping="Hypersonic SQL" 
  |  *    table-name="PART" 
  |  *    create-table="false" 
  |  *    remove-table="false" 
  |  *    alter-table="false"
  |  *   
  |  * @ejb.finder
  |  *   signature="dataregistry.LocalPart findByPrimaryKey(java.lang.String, java.lang.Integer)"
  |  *   query="SELECT OBJECT(o) FROM Part o WHERE o.partNumber = ?1 AND o.revision = ?2"
  |  *   view-type="local"
  |  */
  | public abstract class PartBean implements EntityBean {
  | 
  |     /**
  |      * @ejb.persistence column-name="PART_NUMBER" jdbc-type="VARCHAR" sql-type="VARCHAR"
  |      */
  |     public abstract String getPartNumber();
  | 
  |     /**
  |      * @ejb.persistence column-name="REVISION" jdbc-type="NUMERIC" sql-type="NUMERIC"
  |      */
  |     public abstract int getRevision();
  | 
  |     /**
  |      * @ejb.persistence column-name="DESCRIPTION" jdbc-type="VARCHAR" sql-type="VARCHAR"
  |      */
  |     public abstract String getDescription();
  | 
  |     ...
  | }
  | 

I thought that a @jboss.unknown-pk would do it but it's not possible to associate more than one column-name to it.

Thanks in advance.


View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4048712#4048712

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



More information about the jboss-user mailing list