-->
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 sequence and Hibernate mapping
PostPosted: Wed Aug 28, 2013 1:36 am 
Newbie

Joined: Fri Aug 02, 2013 8:24 am
Posts: 9
The oracle-hibernate combination is driving me crazy now.
I have one pojo class (MyTable) and corresponding hbm file (my_table.hbm.xml).
Now I want to make insert into table "my_table".
I want oracle sequence to be used for entry into primary key of this table.
So I updated in my hbm file (my_table.hb,.xml)

Code:
<id name="id" type="big_decimal">
            <column name="id" />
            <generator class="sequence">
                 <param name="sequence">MY_TABLE_ID_SEQ</param>
           </generator>
</id>


The data type used for numbers in oracle is getting mapped to java.maths.BigDecimal.
So in MyTable class I have following entry

Code:
       private BigDecimal id;

      public BigDecimal getId() {
      return this.id;
   }

   public void setId(BigDecimal id) {
      this.id = id;
   }


Now I get error "org.springframework.orm.hibernate3.HibernateSystemException: this id generator generates long, integer, short or string; nested exception is"

As per topic https://forum.hibernate.org/viewtopic.php?f=1&t=985008
I manually change hbm file to

Code:
<id name="id" type="long">
            <column name="id" />
            <generator class="sequence">
                 <param name="sequence">MY_TABLE_ID_SEQ</param>
           </generator>
</id>


And corresponding MyTable class methods to

Code:
private long id;

      public long getId() {
      return this.id;
   }

   public void setId(long id) {
      this.id = id;
   }


But now I get error:
org.springframework.orm.hibernate3.HibernateSystemException: Provided id of the wrong type. Expected: class java.lang.Long, got class java.math.BigDecimal; nested exception is org.hibernate.TypeMismatchException: Provided id of the wrong type. Expected: class java.lang.Long, got class java.math.BigDecimal

Has anyone got similar issue? Please kindly reply.
Thank is advance.


Top
 Profile  
 
 Post subject: Re: Oracle sequence and Hibernate mapping
PostPosted: Fri Aug 30, 2013 7:43 am 
Newbie

Joined: Fri Aug 02, 2013 8:24 am
Posts: 9
Ok, So I did many trial and errors on this and what I have found out that

1. When column is of data type Number(7,0) I get int in Hibernate mapping files.
2. When column is of data type Number(11,0) I get long in Hibernate mapping files.
3. When column is of data type Number(19,0) I get big_decimal in Hibernate mapping files.

So I changed my column from Number(19,0) to Number(11,0) and regenerated hbm files.
The insertion in sequence is successful but again findById fails with error.

17:17:38,250 INFO [STDOUT] Hibernate: select MY_TABLE_ID_SEQ.nextval from dual
17:17:38,829 ERROR [] Provided id of the wrong type. Expected: class java.lang.Long, got class java.math.BigDecimal; nested exception is org.hibernate.TypeMismatchException: Provided id of the wrong type. Expected: class java.lang.Long, got class java.math.BigDecimal
org.springframework.orm.hibernate3.HibernateSystemException: Provided id of the wrong type. Expected: class java.lang.Long, got class java.math.BigDecimal; nested exception is org.hibernate.TypeMismatchException: Provided id of the wrong type. Expected: class java.lang.Long, got class java.math.BigDecimal
at org.springframework.orm.hibernate3.SessionFactoryUtils.convertHibernateAccessException(SessionFactoryUtils.java:679)
at org.springframework.orm.hibernate3.HibernateAccessor.convertHibernateAccessException(HibernateAccessor.java:412)
at org.springframework.orm.hibernate3.HibernateTemplate.doExecute(HibernateTemplate.java:411)
at org.springframework.orm.hibernate3.HibernateTemplate.executeWithNativeSession(HibernateTemplate.java:374)
at org.springframework.orm.hibernate3.HibernateTemplate.get(HibernateTemplate.java:512)
at org.springframework.orm.hibernate3.HibernateTemplate.get(HibernateTemplate.java:506)
at com.dao.impl.PersistenceManagerHibernateImpl.findById(PersistenceManagerHibernateImpl.java:452)
.
.
.
.

at java.lang.Thread.run(Thread.java:662)
Caused by: org.hibernate.TypeMismatchException: Provided id of the wrong type. Expected: class java.lang.Long, got class java.math.BigDecimal
at org.hibernate.event.def.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:84)
at org.hibernate.impl.SessionImpl.fireLoad(SessionImpl.java:878)
at org.hibernate.impl.SessionImpl.get(SessionImpl.java:815)
at org.hibernate.impl.SessionImpl.get(SessionImpl.java:808)
at org.springframework.orm.hibernate3.HibernateTemplate$1.doInHibernate(HibernateTemplate.java:519)
at org.springframework.orm.hibernate3.HibernateTemplate.doExecute(HibernateTemplate.java:406)

Please can anyone guide on this?

Thank you
Geeta


Top
 Profile  
 
 Post subject: Re: Oracle sequence and Hibernate mapping
PostPosted: Mon Sep 02, 2013 5:32 am 
Newbie

Joined: Fri Aug 02, 2013 8:24 am
Posts: 9
Ok, I finally got this resolved.
I failed to make a note that it is failing at some other point rather than record which I inserted.
I need to now alter all my primary keys from Number(19,0) to Number(11,0) in order to get "long" in HBM files rather than "big_decimal" as "long" is good enough in my case.
This will resolve my issue.


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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.