Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Hibernate: using oracle sequence

 
chanaporn temaismithi
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I tried to save very simple value to oracle by using sequence as my id generator. I stepped thru the object value and confirmed that my id field is obtained correctly from the sequence but when hibernate save the object to database somehow the id field turns out to be some funny value and when reading it back i got this error

java.lang.ArrayIndexOutOfBoundsException: -124
at oracle.sql.LnxLibThin.lnxnuc(LnxLibThin.java:6036)
at oracle.sql.NUMBER.toInt(NUMBER.java:412)
at oracle.jdbc.dbaccess.DBConversion.NumberBytesToInt(DBConversion.java:2884)

I did try to use long type but also get this error
java.sql.SQLException: Overflow Exception
at oracle.sql.NUMBER.toLong(NUMBER.java:376)
at oracle.jdbc.dbaccess.DBConversion.NumberBytesToLong(DBConversion.java:2915)

This is my mapping:

<class name="de.gloegl.road2hibernate.Event" table="EVENTS">
<id name="id" column="id" type="integer">
<generator class="sequence">
<param name="sequence">event_sequence</param>
</generator>
</id>
<property name="date" column="eventdate" type="timestamp"/>
<property name="title" column="eventtitle"/>
</class>

The same code works just fine with HSQL or by reading the prepopulated value from oracle. Is there anything I did wrong?

Thank you,
CT
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

As I understand it the only types you can use for sequences are long, int or short.
 
chanaporn temaismithi
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i have tried long and int too but same problem, saved value was wrong -> error when read back.
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hmm. What the error seems to be saying is the value returned from your sequence is bigger than that accepted by an int. What is the value in you sequence?


The same code works just fine with HSQL or by reading the prepopulated value from oracle

Can you explain this too? What are you doing with HQL exactly?
[ August 13, 2004: Message edited by: Paul Sturrock ]
 
alexandre alexandre
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello chanaporn temaismithi,

I've the same probleme as you.
Have you find a solution ?

thanks
 
Wu LI
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I met the same problem .I use hibernate 2.1.6. who can help me
 
Wu LI
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
chanaporn temaismithi:
My problem has resolved. The reason is the dialect used is net.sf.hibernate.dialect.Oracle9Dialect,but my dirver is older though it is
for oracle 9i.I get a newer oracle 9i driver , it disappear .Hope this can
help you.
 
jonathan qin
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Change your orcale driver to fit the DB, and try again.
I think you can solve the problem.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic