File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Object Relational Mapping and the fly likes Hibernate: using oracle sequence Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Hibernate: using oracle sequence" Watch "Hibernate: using oracle sequence" New topic
Author

Hibernate: using oracle sequence

chanaporn temaismithi
Greenhorn

Joined: Aug 11, 2004
Posts: 2
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

Joined: Apr 14, 2004
Posts: 10336


As I understand it the only types you can use for sequences are long, int or short.


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
chanaporn temaismithi
Greenhorn

Joined: Aug 11, 2004
Posts: 2
i have tried long and int too but same problem, saved value was wrong -> error when read back.
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

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

Joined: Sep 07, 2004
Posts: 2
Hello chanaporn temaismithi,

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

thanks
Wu LI
Greenhorn

Joined: Nov 30, 2002
Posts: 4
I met the same problem .I use hibernate 2.1.6. who can help me
Wu LI
Greenhorn

Joined: Nov 30, 2002
Posts: 4
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

Joined: Sep 22, 2004
Posts: 1
Change your orcale driver to fit the DB, and try again.
I think you can solve the problem.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Hibernate: using oracle sequence
 
Similar Threads
Hibernate
Hibernate is saving the id as -E.000E-78
junk values for the id property
ORA-00001: unique constraint exception
out of range error