-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: Oracle 10g, Sequences, and Hibernate annotations
PostPosted: Wed Feb 13, 2008 12:07 am 
Newbie

Joined: Tue Feb 12, 2008 11:36 pm
Posts: 1
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


Top
 Profile  
 
 Post subject: Try java.lang.Long
PostPosted: Thu Apr 10, 2008 10:22 am 
Newbie

Joined: Tue Apr 01, 2008 3:34 pm
Posts: 10
I'm using non-primitives with Oracle 10g and no problems. I'm not sure about your use of not-null in your type declaration. I think type mappings don't have a notion of null/not-null :-/ I have (for the moment, this needs tuning to support float and double values in the database)...

Code:
<hibernate-reverse-engineering>
<type-mapping>
  <sql-type jdbc-type="DECIMAL" hibernate-type="java.lang.Long"/>
</type-mapping>
</hibernate-reverse-engineering>


...and this works for me.

Hope that helps.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 10, 2008 12:03 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
type-mapping does have a notion of not-null to be able to say if a numeric field needs to be typed as long or java.lang.Long

-max

_________________
Max
Don't forget to rate


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.