0 Replies Latest reply on Jul 1, 2007 1:43 AM by ken2

    Q) Usage of @Generated(GenerationTime.ALWAYS)

    ken2

      Hi!
      I seam-gen to build platform to start my application development. I generated codes using seam generate-entities from DB which has ID generated by DB itself. So, I tried to add @Generated(GenerationTime.ALWAYS) to ID, but it caused the error as shown below.
      Am I misunderstanding something? Is there a way to enable generated code respecting DB generated IDs?

      Table scheme

      Column | Type | Modifiers
      ---------+---------+----------------------------------------------------
      id | integer | not null default nextval('users_id_seq'::regclass)
      name | text | not null
      address | text | not null
      email | text |
      tel | text |
      Indexes:
      "users_pkey" PRIMARY KEY, btree (id)

      package jp.tydfam.test1;
      // Generated 2007/07/01 13:46:57 by Hibernate Tools 3.2.0.b9
      
      import javax.persistence.Column;
      import javax.persistence.Entity;
      import javax.persistence.Id;
      import javax.persistence.Table;
      
      import org.hibernate.annotations.Generated;
      import org.hibernate.annotations.GenerationTime;
      import org.hibernate.validator.NotNull;
      
      /**
       * Users generated by hbm2java
       */
      @Entity
      @Table(name = "users", schema = "public")
      public class Users implements java.io.Serializable {
      
       private int id;
       private String name;
       private String address;
       private String email;
       private String tel;
      
       public Users() {
       }
      
       public Users(int id, String name, String address) {
       this.id = id;
       this.name = name;
       this.address = address;
       }
       public Users(int id, String name, String address, String email, String tel) {
       this.id = id;
       this.name = name;
       this.address = address;
       this.email = email;
       this.tel = tel;
       }
      
       @Id
       @Generated(GenerationTime.ALWAYS)
       @Column(name = "id", unique = true, nullable = false, insertable=false, updatable=false)
       @NotNull
       public int getId() {
       return this.id;
       }
      
       public void setId(int id) {
       this.id = id;
       }
      
       @Column(name = "name", nullable = false)
       @NotNull
       public String getName() {
       return this.name;
       }
      
       public void setName(String name) {
       this.name = name;
       }
       : : :
      
      }
      

      Error log in server.log (partial)

      : : :
      2007-07-01 13:52:32,909 DEBUG [org.hibernate.cfg.AnnotationBinder] Processing annotations of jp.tydfam.test1.Users.id
      2007-07-01 13:52:32,909 DEBUG [org.hibernate.cfg.Ejb3Column] Binding column id unique true
      2007-07-01 13:52:32,909 DEBUG [org.hibernate.cfg.AnnotationBinder] id is an id
      2007-07-01 13:52:32,909 DEBUG [org.hibernate.cfg.annotations.SimpleValueBinder] building SimpleValue for id
      2007-07-01 13:52:32,909 DEBUG [org.hibernate.cfg.annotations.PropertyBinder] Building property id
      2007-07-01 13:52:32,910 DEBUG [org.jboss.ejb3.ServiceDelegateWrapper] Starting failed persistence.units:ear=test1.ear,unitName=test1
      java.lang.NullPointerException
      at org.hibernate.cfg.annotations.PropertyBinder.make(PropertyBinder.java:145)
      at org.hibernate.cfg.AnnotationBinder.bindId(AnnotationBinder.java:1738)
      at org.hibernate.cfg.AnnotationBinder.processElementAnnotations(AnnotationBinder.java:1180)
      at org.hibernate.cfg.AnnotationBinder.bindClass(AnnotationBinder.java:710)
      at org.hibernate.cfg.AnnotationConfiguration.processArtifactsOfType(AnnotationConfiguration.java:452)
      : : :