1 Reply Latest reply on Mar 28, 2007 11:49 AM by Mike Dougherty

    @Column Annotation doesn't seem to work...

    Eric Anderson Newbie

      It seems the @Column annotation doesn't work for some reason?
      using
      jboss-4.0.5.GA

      EJB 3.0

      
      @Entity
      @NamedQueries({
      @NamedQuery(name = "SdsDataLoadPat.findAll", query = "select o from SdsDataLoadPat o"),
      @NamedQuery(name = "SdsDataLoadPat.findAllbyId", query = "select o from SdsDataLoadPat as o WHERE o.loadSeqNo = :loadSeqNo AND o.setId = :setId")
      })
      @Table(name = "SDS_DATA_LOAD_PAT")
      @IdClass(SdsDataLoadPatPK.class)
      public class SdsDataLoadPat implements Serializable {
       @Column(name="ADDRESS_CITY")
       private String addressCity;
      
      .....
      
       @Id
       @Column(name="LOAD_SEQ_NO", nullable = false)
       private Long loadSeqNo;
      
       @Id
       @Column(name="SET_ID", nullable = false)
       private Long setId;
      
       private String ssn;
       @Column(name="STATUS_CODE")
       private String statusCode;
       private String suffix;
      
      }
      
      
      


      This is the sql shown from the DEBUG

      
      2007-03-26 08:16:05,643 DEBUG [org.hibernate.util.JDBCExceptionReporter] could not execute query [select sdsdataloa0_.loadSeqNo as loadSeqNo24_,
      .............
      sdsdataloa0_.USIIS_ID as USIIS67_24_ from SDS_DATA_LOAD_PAT sdsdataloa0_ where sdsdataloa0_.loadSeqNo=? and sdsdataloa0_.setId=?]
      
      



      The sql is being translated using the field name, not the @column name. (sdsdataloa0_.loadSeqNo=? and sdsdataloa0_.setId=?)

      Anyone have a clue why?

        • 1. Re: @Column Annotation doesn't seem to work...
          Mike Dougherty Newbie

          I can't answer the "why", but I had the same problem. I worked around it by putting the @Column annotation in the Primary Key class.

          public class Foo {
          
           @Id
           public Long getFooId() {
           }
          
           @Id
           public Long getBarId() {
           }
          
           public static class FooPK {
          
           @Column(name="FOO_ID")
           public Long getFooId() {
           }
           @Column(name="BAR_ID")
           public Long getBarId() {
           }
           }
          }
          


          Seems to have given me the result I needed. But I'm not sure how this will affect future mappings, annotations, etc.