This content has been marked as final.
Show 6 replies
-
1. Re: problem with @GeneratedValue + oracle
francof Nov 21, 2008 7:22 PM (in response to peduardo)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
peduardo Nov 21, 2008 7:37 PM (in response to peduardo)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
francof Nov 21, 2008 8:16 PM (in response to peduardo)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 Nov 21, 2008 8:17 PM (in response to peduardo)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
-
5. Re: problem with @GeneratedValue + oracle
peduardo Nov 21, 2008 11:00 PM (in response to peduardo)thanks... now its ok...
-
6. Re: problem with @GeneratedValue + oracle
ino80 Jun 5, 2009 9:19 AM (in response to peduardo)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; } }