6 Replies Latest reply on Jun 5, 2009 9:19 AM by Ivaldo Nascimento Oliveira

    problem with @GeneratedValue + oracle

    I need a  real name Newbie
      Hello, i'm using seam + oracle but when i start jboss server, i have the follow issue:


      org.hibernate.AnnotationException: Unknown Id.generator: MYSEQUENCE.

      i have:

      @SequenceGenerator( name = "MYSEQUENCE", sequenceName = "MYSCHEMA.MYSEQUENCE" )
      @GeneratedValue( strategy = GenerationType.SEQUENCE, generator = "MYSEQUENCE" )

      obs: i create my projects using seam-gen.

      somebody know what is this??? when i have to do?

      thanks
        • 1. Re: problem with @GeneratedValue + oracle
          Franco Fernandes Novice

          You do not have a sequence named MYSEQUENCE in your database.


          follow this example




          @GeneratedValue(strategy=GenerationType.SEQUENCE, generator = "BURST_SEQ")
          @SequenceGenerator(name="BURST_SEQ", sequenceName = "burst_seq", allocationSize=1)
          public Integer getBurstId() {
               return this.burstId;
          }
          
          




          It uses an existing sequence object in your Oracle schema called burst_seq indicated here by sequenceName


          generator="BURST_SEQ" and SequenceGenerator(name="BURST_SEQ"
          should have the same value, you can name it anything.





          • 2. Re: problem with @GeneratedValue + oracle
            I need a  real name Newbie
            Sorry Franco Fernandes but i have the same problem.

            my SQL sequence in my database:

            CREATE SEQUENCE  "BD_ESCRITORIO"."SEQ_INSTITUICAO"  MINVALUE 1 MAXVALUE 9999999999999999999999999999 INCREMENT BY 1 START WITH 1 CACHE 20 NOORDER  NOCYCLE ;

            in my class:

            @SequenceGenerator( name = "SEQ_INSTITUICAO", sequenceName = "BD_ESCRITORIO.SEQ_INSTITUICAO",allocationSize=1  )

            @Id
                 @GeneratedValue( strategy = GenerationType.SEQUENCE, generator = "SEQ_INSTITUICAO" )
                 @Column(name = "CD_INSTITUICAO", unique = true, nullable = false, precision = 22, scale = 0)     
                      
                 public BigDecimal getCdInstituicao() {
                      return this.cdInstituicao;
                 }


            exception:

            org.hibernate.AnnotationException: Unknown Id.generator: SEQ_INSTITUICAO



            • 3. Re: problem with @GeneratedValue + oracle
              Franco Fernandes Novice

              Try dropping schema name from sequenceName

              so replace
              sequenceName = "BD_ESCRITORIO.SEQ_INSTITUICAO"
              with
              sequenceName = "SEQ_INSTITUICAO"

              • 4. Re: problem with @GeneratedValue + oracle
                Andre Eugenio Newbie

                Hi Paulo,


                I'm using Seam, Oracle, Hibernate and i don't have problems to use Sequence. See the following code


                @Id
                @GeneratedValue(generator = "generatedValueTbArea")
                @SequenceGenerator(name = "generatedValueTbArea", sequenceName = "SEQ_AREA")
                
                



                I guess worth try to remove strategy = GenerationType.SEQUENCE in @GeneratedValue.


                Hope it helps.


                /peace

                • 6. Re: problem with @GeneratedValue + oracle
                  Ivaldo Nascimento Oliveira Newbie

                  For registration of solution, use the follow code:


                  @Entity
                  @Table(name = "COUNTRY")
                  @SequenceGenerator(name = "contrySeq", sequenceName = "COUNT_SEQ")  
                  public class Country implements java.io.Serializable {
                    private long id;
                    private String name;
                  
                    @Id
                    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "countrySeq")
                    @Column(name = "COUNTRY_ID", unique = true, nullable = false, precision = 3, scale = 0) // is optional
                    @NotNull // is optional
                    public long getId() {
                      return this.id;
                    }
                    public void setId(long id) {
                      this.id = id;
                    }
                    public setName(String name) {
                      this.name = name;
                    }
                    public getName() {
                      return this.name;
                    }
                  }