-->
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.  [ 19 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: How to map Oracle 8i NUMBER(20) column to java long?
PostPosted: Mon Aug 01, 2005 5:48 pm 
Newbie

Joined: Wed Aug 25, 2004 10:43 pm
Posts: 14
Location: NJ
We define all numbers in our legacy DB as oracle NUMBER types, commonly with a size of 20.

All of the properties in our objects that represent those columns are defined as long primitives.

How can I successfully load an Oracle NUMBER type into a java long? From the reading I've done on the docs, forums and google, it seems that oracle NUMBERs are types as BigIntegers in hibernate. This won't work for our legacy schema/object model.

Is there a solution? I tried to create a custom dialect by extending OracleDialect and adding
Code:
registerColumnType( Types.INTEGER, "number(19,0)" );

but this didn't do anything..

Is the only solution to change our DB or objects??

Thanks!
Ian.

Hibernate version:
3.0.5

Mapping documents:
<class name="com.cirqit.core.headers.CqtUserHdr" table="PBVUSER">
<id name="userNbr" column="USER_NBR" type="long" unsaved-value="-1"/>
</class>

Full stack trace of any exception that occurs:
org.hibernate.exception.GenericJDBCException: could not execute query
at org.hibernate.exception.ErrorCodeConverter.handledNonSpecificException(ErrorCodeConverter.java:92)
at org.hibernate.exception.ErrorCodeConverter.convert(ErrorCodeConverter.java:80)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.loader.Loader.doList(Loader.java:1596)
at org.hibernate.loader.Loader.list(Loader.java:1577)
at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:395)
at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:271)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:844)
at org.hibernate.impl.QueryImpl.list(QueryImpl.java:74)
at com.cirqit.jsp.services.ClientEstimateService.getRFQEstimateCollector(ClientEstimateService.java:2576)
at com.cirqit.jsp.pricing.CqtEstimateOverviewPageHandler.preProcessPage(CqtEstimateOverviewPageHandler.java:559)
at com.cirqit.jsp.CqtListPageHandlerBase.processPage(CqtListPageHandlerBase.java:360)
at com.cirqit.jsp.CqtPageHandlerBase.start(CqtPageHandlerBase.java:1129)
at org.apache.jsp.clnt_005festimate_005foverview_jsp._jspService(clnt_005festimate_005foverview_jsp.java:535)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:133)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:311)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:301)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:248)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:284)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:204)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:256)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:151)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:564)
at org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:245)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:199)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:151)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:564)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:195)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:151)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:164)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:149)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:564)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:156)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:151)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:564)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:972)
at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:211)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:805)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:696)
at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:605)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:677)
at java.lang.Thread.run(Thread.java:595)
Caused by: java.sql.SQLException: Fail to convert to internal representation
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:180)
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:222)
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:285)
at oracle.jdbc.driver.OracleStatement.getLongValue(OracleStatement.java:3729)
at oracle.jdbc.driver.OracleStatement.getIntValue(OracleStatement.java:3675)
at oracle.jdbc.driver.OracleResultSetImpl.getInt(OracleResultSetImpl.java:332)
at oracle.jdbc.driver.OracleResultSet.getInt(OracleResultSet.java:1551)
at org.apache.commons.dbcp.DelegatingResultSet.getInt(DelegatingResultSet.java:220)
at org.hibernate.type.IntegerType.get(IntegerType.java:26)
at org.hibernate.type.NullableType.nullSafeGet(NullableType.java:77)
at org.hibernate.type.NullableType.nullSafeGet(NullableType.java:68)
at org.hibernate.type.ManyToOneType.hydrate(ManyToOneType.java:84)
at org.hibernate.persister.entity.BasicEntityPersister.hydrate(BasicEntityPersister.java:1690)
at org.hibernate.loader.Loader.loadFromResultSet(Loader.java:991)
at org.hibernate.loader.Loader.instanceNotYetLoaded(Loader.java:942)
at org.hibernate.loader.Loader.getRow(Loader.java:855)
at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:305)
at org.hibernate.loader.Loader.doQuery(Loader.java:412)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:218)
at org.hibernate.loader.Loader.doList(Loader.java:1593)

Name and version of the database you are using:
Oracle 8i, using classes12.zip for JDBC, which is the default 8i driver I believe


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 01, 2005 6:28 pm 
Regular
Regular

Joined: Wed Jan 07, 2004 5:16 pm
Posts: 65
Location: CA, USA
You could write your own custom UserType - you can then convert from whatever column type to whatever property type you need to.

See pg 202 in Hibernate In Action for more info.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 02, 2005 10:10 am 
Newbie

Joined: Wed Aug 25, 2004 10:43 pm
Posts: 14
Location: NJ
khooke wrote:
You could write your own custom UserType - you can then convert from whatever column type to whatever property type you need to.

See pg 202 in Hibernate In Action for more info.


Hm, I see. Surely, other Oracle users have encountered this in the past. Does anybody have a link to an example of implementing this type of UserType object? It seems there are a lot of methods to implement, and I don't have Hibernate In Action.

But, on the other hand, are Oracle users really just expected to use BigDecimal/BigInteger object in all of their object to map to number columns in their DB?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 03, 2005 12:46 pm 
Newbie

Joined: Wed Aug 25, 2004 10:43 pm
Posts: 14
Location: NJ
Are there any examples on the web of implementing a UserType?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 03, 2005 3:46 pm 
Expert
Expert

Joined: Sat Jun 12, 2004 4:49 pm
Posts: 915
you can use hibernate long type like this

...
<property name="property_name" type="long" column="COLUMN_NAME" length="20" />
...

and in class like this :

private Long property_name;

or

private long property_name;



regards


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 03, 2005 4:41 pm 
Newbie

Joined: Wed Aug 25, 2004 10:43 pm
Posts: 14
Location: NJ
Thanks for the response.

I'd tried your suggestion, but got the same error.

Code:
    <class name="com.cirqit.core.headers.CqtUserHdr" table="PBVUSER">
        <id name="userNbr" column="USER_NBR" type="long" unsaved-value="-1" length="20" />
    </class>


CqtUserHdr has this:
Code:
    protected long m_lUserNbr = -1;
    public long getUserNbr()
    {
        return m_lUserNbr;
    }

    public void setUserNbr( long lUserNbr )
    {
        m_lUserNbr = lUserNbr;
    }



Gives me the same error:

Code:
org.hibernate.exception.GenericJDBCException: could not execute query
   at org.hibernate.exception.ErrorCodeConverter.handledNonSpecificException(ErrorCodeConverter.java:92)
   at org.hibernate.exception.ErrorCodeConverter.convert(ErrorCodeConverter.java:80)
   at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
   at org.hibernate.loader.Loader.doList(Loader.java:1596)
   at org.hibernate.loader.Loader.list(Loader.java:1577)
   at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:395)
   at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:271)
   at org.hibernate.impl.SessionImpl.list(SessionImpl.java:844)
   at org.hibernate.impl.QueryImpl.list(QueryImpl.java:74)
   at com.cirqit.jsp.services.ClientEstimateService.getRFQEstimateCollector(ClientEstimateService.java:2576)
   at com.cirqit.jsp.pricing.CqtEstimateOverviewPageHandler.preProcessPage(CqtEstimateOverviewPageHandler.java:559)
   at com.cirqit.jsp.CqtListPageHandlerBase.processPage(CqtListPageHandlerBase.java:360)
   at com.cirqit.jsp.CqtPageHandlerBase.start(CqtPageHandlerBase.java:1129)
   at org.apache.jsp.clnt_005festimate_005foverview_jsp._jspService(clnt_005festimate_005foverview_jsp.java:535)
   at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:133)
   at javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
   at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:311)
   at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:301)
   at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:248)
   at javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:284)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:204)
   at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:256)
   at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:151)
   at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:564)
   at org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:245)
   at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:199)
   at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:151)
   at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:564)
   at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:195)
   at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:151)
   at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:164)
   at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:149)
   at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:564)
   at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:156)
   at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:151)
   at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:564)
   at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:972)
   at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:211)
   at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:805)
   at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:696)
   at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:605)
   at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:677)
   at java.lang.Thread.run(Thread.java:595)
Caused by: java.sql.SQLException: Fail to convert to internal representation
   at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:180)
   at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:222)
   at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:285)
   at oracle.jdbc.driver.OracleStatement.getLongValue(OracleStatement.java:3729)
   at oracle.jdbc.driver.OracleResultSetImpl.getLong(OracleResultSetImpl.java:338)
   at oracle.jdbc.driver.OracleResultSet.getLong(OracleResultSet.java:1563)
   at org.apache.commons.dbcp.DelegatingResultSet.getLong(DelegatingResultSet.java:221)
   at org.hibernate.type.LongType.get(LongType.java:26)
   at org.hibernate.type.NullableType.nullSafeGet(NullableType.java:77)
   at org.hibernate.type.NullableType.nullSafeGet(NullableType.java:68)
   at org.hibernate.type.ManyToOneType.hydrate(ManyToOneType.java:84)
   at org.hibernate.persister.entity.BasicEntityPersister.hydrate(BasicEntityPersister.java:1690)
   at org.hibernate.loader.Loader.loadFromResultSet(Loader.java:991)
   at org.hibernate.loader.Loader.instanceNotYetLoaded(Loader.java:942)
   at org.hibernate.loader.Loader.getRow(Loader.java:855)
   at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:305)
   at org.hibernate.loader.Loader.doQuery(Loader.java:412)
   at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:218)
   at org.hibernate.loader.Loader.doList(Loader.java:1593)
   ... 40 more



It really seems like the Oracle driver doesn't like longs or something.. :(


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 03, 2005 4:51 pm 
Expert
Expert

Joined: Sat Jun 12, 2004 4:49 pm
Posts: 915
I have table defined with :
rbr number

and class field Long

It work with hibernate 2 and 3 (and last cvs)

try define class field Long

I use oracle 9 and jdbc 10g , but I think that it isn't important

try define long in xml and Long in java

regards


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 03, 2005 5:13 pm 
Expert
Expert

Joined: Sat Jun 12, 2004 4:49 pm
Posts: 915
I try long class field for you and it work for me (java 5.0,hibernate 3.1, jdbc 10g), but it work before for oracle 8, jdbc for oracle 8 and java 1.4

You use too old driver - try new driver ojdbc14.jar from otn.oracle.com

regards


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 03, 2005 5:16 pm 
Newbie

Joined: Wed Aug 25, 2004 10:43 pm
Posts: 14
Location: NJ
Hm, I changed the class field to a Long instead of a long, and recieve the same error.

I'm using Oracle 8i with the 8i driver.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 03, 2005 5:18 pm 
Newbie

Joined: Wed Aug 25, 2004 10:43 pm
Posts: 14
Location: NJ
Are there any problems/concerns when using that newer drivers with our older database?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 03, 2005 5:18 pm 
Newbie

Joined: Wed Aug 25, 2004 10:43 pm
Posts: 14
Location: NJ
Oh, I'm also using Hibernate 3.0.5, not 3.1.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 03, 2005 5:24 pm 
Expert
Expert

Joined: Sat Jun 12, 2004 4:49 pm
Posts: 915
It work with hibernate 3.0.5, too

newer driver work with older databases (not always)

oracle 10g work with oracle9i, but I don't know for oracle 8i - I think that work with 8i , too

You can try driver for oracle 10g, oracle 9i,oracle 8i (for java 1.4, ojdbc14.jar)
try it and use last which work with your databases (newer driver are better,always)

I know that oracle 10g doesn't work with oracle8.0, but you try this driver first - oracle10g is the best driver specially for blob

regards


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 03, 2005 5:25 pm 
Expert
Expert

Joined: Sat Jun 12, 2004 4:49 pm
Posts: 915
I forget this : you have 2 drivers for 8i (one for old jdk 1.2 classes12.zip and newer for jdk 1.4 ojdbc14.jar)


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 03, 2005 5:41 pm 
Newbie

Joined: Wed Aug 25, 2004 10:43 pm
Posts: 14
Location: NJ
Well, on the Oracle JDBC download page for 8i, I only see classes12.zip available, I don't see the ojdbc14.jar driver you're talking about. This driver only seems to be available for newer versions of Oracle.

I am trying the 10g one.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 03, 2005 5:43 pm 
Expert
Expert

Joined: Sat Jun 12, 2004 4:49 pm
Posts: 915
jdbc 10g work with oracle 8.1.7 see http://www.oracle.com/technology/tech/j ... .htm#02_02

regards


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 19 posts ]  Go to page 1, 2  Next

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.