Having a problem mapping sequences with primary keys defined as NUMBER in Oracle 10g XE.
Table is:
Code:
CREATE TABLE "EMPLOYMENT"
( "EMPLOYMENT_ID" NUMBER NOT NULL ENABLE,
"EMPLOYMENT" VARCHAR2(20 BYTE) NOT NULL ENABLE,
"SORTORDER" NUMBER NOT NULL ENABLE,
CONSTRAINT "EMPL_PK" PRIMARY KEY ("EMPLOYMENT_ID")
CREATE SEQUENCE "EMPLOYMENT_SEQ" MINVALUE 1 MAXVALUE 1000000000000000000000000000 INCREMENT BY 1 START WITH 21 CACHE 20 NOORDER NOCYCLE ;
Code:
private BigDecimal employmentId;
....
@SequenceGenerator(
name="EMPLOYMENT_SEQ",
sequenceName="EMPLOYMENT_SEQ"
)
@Id
@Column(name = "EMPLOYMENT_ID", nullable = false, precision = 22, scale = 0)
@GeneratedValue(strategy=GenerationType.SEQUENCE, generator="EMPLOYMENT_SEQ")
public BigDecimal getEmploymentId() {
return this.employmentId;
}
I used Hibernate Tools to generate the annotated java class and added the sequence generator. Hibernate Tools mapped Oracle NUMBER -> BigDecimal, precision 22, scale 0.
---->>> here's the problem
SELECT EMPLOYMENT_SEQ.NEXTVAL FROM DUAL; <-- returns a long
and hibernate doenst' like that it is trying to map a long into a bigdecimal.
Now to get around it, I had to go in and change all the BigDecimal to Long.
Code:
private Long employmentId;
....
public Long getEmploymentId() {
return this.employmentId;
}
Am I missing something? Hibernate Tools won't let you override the identity columns.
so this has no effect in the hibernate.reveng.xml
<type-mapping>
<sql-type jdbc-type="NUMERIC" hibernate-type="long" not-null="true"></sql-type>
</type-mapping>
Hibernate Tools 3.2.0.cr1
Hibernate Core 3.2
Hiberate Annotations 3.2.1.GA