2 Replies Latest reply on Jan 18, 2006 4:16 PM by Carlos Duarte

    Composite primary keys don't work?

    Carlos Duarte Newbie

      Hi all, I've been struggling to start a jboss+seam application. Everything seems to be ok except a major stopper problem. Composite PKs appear to not work at all, including the CRUD application that is automatically generated by hibernate tools.

      An example; I have this table PARAMETIZATION that contains 10 plain columns but none PK.
      So I end up with Parametization and ParametizationId:


      public class Parametization implements java.io.Serializable {
       private ParametizationId id;
       @Id @EmbeddedId
       @AttributeOverrides( {
       @AttributeOverride(name="planId", column=@Column(name="PLAN_ID", unique=false, nullable=false, insertable=true, updatable=true, len
      gth=30) ),
       @AttributeOverride(name="moduleId", column=@Column(name="MODULE_ID", unique=false, nullable=false, insertable=true, updatable=true,
       length=30) ), (...)

      public class ParametizationId implements java.io.Serializable {
       private String planId;
       private String moduleId;
       private String productName;

      When the entitymanager query for Parametization, I see on logs a correct query being made:
      select parametiza0_.PLAN_ID as PLAN1_557_, parametiza0_.MODULE_ID as MODULE2_557_, parametiza0_.PRODUCT_NAME as PRODUCT3_557_, parametiza0_.PARAM_NAME as PARAM4_557_, parametiza0_.NUM_INTERVAL_FROM as NUM5_557_, parametiza0_.NUM_INTERVAL_TO as NUM6_557_, parametiza0_.NUM_VALUE as NUM7_557_, parametiza0_.CHAR_PARAM_VALUE as CHAR8_557_, parametiza0_.CHAR_VALUE as CHAR9_557_, parametiza0_.PARAM_TYPE as PARAM10_557_ from PARAMETIZATION parametiza0_

      This query returns the table data. On the Finder bean, it actually returns the real number of lines, but all list objects are null.
       parametizationList = (List<Parametization>) query.setMaxResults(pageSize)
       log.info("got: "+parametizationList.size()+" results"); // CORRECT VALUE HERE
       for (Parametization p : parametizationList) {
       if (p == null)
       log.info("NULL"); // IT FALLS HERE ALL CASES
       log.info("got: "+p.getId().getPlanId()+" "+p.getId().getModuleId());

      I'm using jboss403sp1 and jboss-seam-1.0beta1 and jboss-seam-cvs as of 11-jan-06 (neither works), with hibernate-annotations.jar hibernate3.jar updated from HibernateTools-3.1.0.N200512200952

      Oh, if I inline the keys in the entity bean and set only one to @Id it works, but I'm afraid this might cause troubles on updates and deletes.

      Thanks in advance for any help.