-->
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: Confusion of DECIMAL and NUMERIC column types in DB2
PostPosted: Sat Nov 24, 2007 11:07 am 
Newbie

Joined: Fri Nov 23, 2007 4:07 pm
Posts: 1
I faced the same problem as as described in HHH-2261 but for DB2 ver 9.1 instead of MySQL. As a workaround, I subclassed DB2Dialect as suggested in the issue details and my problem was resolved. Since, I'm new to hibernate I'm a bit concerned with this solution for the following reasons: (a) I searched everywhere to see if any other DB2 users experienced this problem and I couldn't find anyone. (b) I would like to avoid having my own custom subclass and use the provided DB2Dialect from Hibernate. Can someone please confirm that this is a problem and the best option for a workaround?

The following are some details illustrating this problem on DB2.
Hibernate version:
3.2.4 (from JBoss 4.2.2 GA)

Name and version of the database you are using:
DB2 v. 9.1
Type 4 JDBC Driver: com.

Example of DB2 table representing a numeric as a decimal data type:
db2 => create table test (
db2 (cont.) => NUMERIC_ENTRY NUMERIC(10,2),
db2 (cont.) => DECIMAL_ENTRY DECIMAL(10,2));
DB20000I The SQL command completed successfully.
db2 => describe select * from test;

SQLDA Information

sqldaid : SQLDA sqldabc: 1136 sqln: 20 sqld: 2

Column Information

sqltype sqllen sqlname.data sqlname.length
-------------------- ------ ------------------------------ --------------
485 DECIMAL 10, 2 NUMERIC_ENTRY 13
485 DECIMAL 10, 2 DECIMAL_ENTRY 13



The following is the error I get when starting my application:
05:40:48,677 WARN [ServiceController] Problem starting service persistence.units:ear=osmnew.ear,unitName=osmnew
javax.persistence.PersistenceException: org.hibernate.HibernateException: Wrong column type: AMOUNT, expected: numeric(10,0)
at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:720)
at org.hibernate.ejb.HibernatePersistence.createContainerEntityManagerFactory(HibernatePersistence.java:127)
at org.jboss.ejb3.entity.PersistenceUnitDeployment.start(PersistenceUnitDeployment.java:246)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.jboss.ejb3.ServiceDelegateWrapper.startService(ServiceDelegateWrapper.java:103)
at org.jboss.system.ServiceMBeanSupport.jbossInternalStart(ServiceMBeanSupport.java:289)
at org.jboss.system.ServiceMBeanSupport.jbossInternalLifecycle(ServiceMBeanSupport.java:245)
at sun.reflect.GeneratedMethodAccessor578.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:155)
at org.jboss.mx.server.Invocation.dispatch(Invocation.java:94)
at org.jboss.mx.server.Invocation.invoke(Invocation.java:86)
at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:264)
at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:659)
at org.jboss.system.ServiceController$ServiceProxy.invoke(ServiceController.java:978)
at $Proxy0.start(Unknown Source)
at org.jboss.system.ServiceController.start(ServiceController.java:417)
at sun.reflect.GeneratedMethodAccessor9.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:155)
at org.jboss.mx.server.Invocation.dispatch(Invocation.java:94)
at org.jboss.mx.server.Invocation.invoke(Invocation.java:86)
at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:264)
at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:659)
at org.jboss.mx.util.MBeanProxyExt.invoke(MBeanProxyExt.java:210)
at $Proxy411.start(Unknown Source)
at org.jboss.ejb3.JmxKernelAbstraction.install(JmxKernelAbstraction.java:120)
at org.jboss.ejb3.Ejb3Deployment.startPersistenceUnits(Ejb3Deployment.java:627)
at org.jboss.ejb3.Ejb3Deployment.start(Ejb3Deployment.java:351)
at org.jboss.ejb3.Ejb3Module.startService(Ejb3Module.java:91)
at org.jboss.system.ServiceMBeanSupport.jbossInternalStart(ServiceMBeanSupport.java:289)
at org.jboss.system.ServiceMBeanSupport.jbossInternalLifecycle(ServiceMBeanSupport.java:245)
at sun.reflect.GeneratedMethodAccessor578.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:155)
at org.jboss.mx.server.Invocation.dispatch(Invocation.java:94)
at org.jboss.mx.server.Invocation.invoke(Invocation.java:86)
at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:264)
at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:659)
at org.jboss.system.ServiceController$ServiceProxy.invoke(ServiceController.java:978)
at $Proxy0.start(Unknown Source)
at org.jboss.system.ServiceController.start(ServiceController.java:417)
at sun.reflect.GeneratedMethodAccessor9.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:155)
at org.jboss.mx.server.Invocation.dispatch(Invocation.java:94)
at org.jboss.mx.server.Invocation.invoke(Invocation.java:86)
at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:264)
at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:659)
at org.jboss.mx.util.MBeanProxyExt.invoke(MBeanProxyExt.java:210)
at $Proxy33.start(Unknown Source)
at org.jboss.ejb3.EJB3Deployer.start(EJB3Deployer.java:512)
at sun.reflect.GeneratedMethodAccessor249.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:155)
at org.jboss.mx.server.Invocation.dispatch(Invocation.java:94)
at org.jboss.mx.interceptor.AbstractInterceptor.invoke(AbstractInterceptor.java:133)
at org.jboss.mx.server.Invocation.invoke(Invocation.java:88)
at org.jboss.mx.interceptor.ModelMBeanOperationInterceptor.invoke(ModelMBeanOperationInterceptor.java:142)
at org.jboss.mx.interceptor.DynamicInterceptor.invoke(DynamicInterceptor.java:97)
at org.jboss.system.InterceptorServiceMBeanSupport.invokeNext(InterceptorServiceMBeanSupport.java:238)
at org.jboss.wsf.container.jboss42.DeployerInterceptor.start(DeployerInterceptor.java:87)
at org.jboss.deployment.SubDeployerInterceptorSupport$XMBeanInterceptor.start(SubDeployerInterceptorSupport.java:188)
at org.jboss.deployment.SubDeployerInterceptor.invoke(SubDeployerInterceptor.java:95)
at org.jboss.mx.server.Invocation.invoke(Invocation.java:88)
at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:264)
at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:659)
at org.jboss.mx.util.MBeanProxyExt.invoke(MBeanProxyExt.java:210)
at $Proxy34.start(Unknown Source)
at org.jboss.deployment.MainDeployer.start(MainDeployer.java:1025)
at org.jboss.deployment.MainDeployer.start(MainDeployer.java:1015)
at org.jboss.deployment.MainDeployer.deploy(MainDeployer.java:819)
at org.jboss.deployment.MainDeployer.deploy(MainDeployer.java:782)
at sun.reflect.GeneratedMethodAccessor20.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:155)
at org.jboss.mx.server.Invocation.dispatch(Invocation.java:94)
at org.jboss.mx.interceptor.AbstractInterceptor.invoke(AbstractInterceptor.java:133)
at org.jboss.mx.server.Invocation.invoke(Invocation.java:88)
at org.jboss.mx.interceptor.ModelMBeanOperationInterceptor.invoke(ModelMBeanOperationInterceptor.java:142)
at org.jboss.mx.server.Invocation.invoke(Invocation.java:88)
at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:264)
at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:659)
at org.jboss.mx.util.MBeanProxyExt.invoke(MBeanProxyExt.java:210)
at $Proxy9.deploy(Unknown Source)
at org.jboss.deployment.scanner.URLDeploymentScanner.deploy(URLDeploymentScanner.java:421)
at org.jboss.deployment.scanner.URLDeploymentScanner.scan(URLDeploymentScanner.java:610)
at org.jboss.deployment.scanner.AbstractDeploymentScanner$ScannerThread.doScan(AbstractDeploymentScanner.java:263)
at org.jboss.deployment.scanner.AbstractDeploymentScanner$ScannerThread.loop(AbstractDeploymentScanner.java:274)
at org.jboss.deployment.scanner.AbstractDeploymentScanner$ScannerThread.run(AbstractDeploymentScanner.java:225)
Caused by: org.hibernate.HibernateException: Wrong column type: AMOUNT, expected: numeric(10,0)
at org.hibernate.mapping.Table.validateColumns(Table.java:261)
at org.hibernate.cfg.Configuration.validateSchema(Configuration.java:1083)
at org.hibernate.tool.hbm2ddl.SchemaValidator.validate(SchemaValidator.java:116)
at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:317)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1294)
at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:713)
... 98 more


Top
 Profile  
 
 Post subject: DB2 datatypes
PostPosted: Tue Feb 03, 2009 5:44 pm 
Newbie

Joined: Wed Jul 02, 2008 1:56 pm
Posts: 1
DB2 v9.5 and Hibernate 3.2.4.sp1 still behaves as described

1. CHAR(>1) are generated as Strings but then validate complains they aren't VARCHAR
2. DECIMAL(p, s) are generated as Big Decimal but then validate complains they aren't NUMERIC (even if you change the datatype to NUMERIC in the DDL DB2 supposedly reports them as DECIMAL, because it still complaons)
3. DECIMAL(p) are generated as int but then validate complains they aren't INTEGER

i believe that reveng.xml can mitigate some or all of this, but i didn't take that approach. i ended up extending the dialect as indicated in the previous post. I did cheat and convert all my CHAR(>1) to VARCHAR (just too lazy to figure out the dialect changes)

import org.hibernate.dialect.DB2Dialect;
import java.sql.Types;

public class FixedDB2Dialect extends DB2Dialect {

public FixedDB2Dialect() {
super();
registerColumnType(Types.INTEGER, "decimal($p)");
registerColumnType(Types.NUMERIC, "decimal($p,$s)");
registerColumnType(Types.DECIMAL, "decimal($p,$s)");
}
}

hope that helps


Top
 Profile  
 
 Post subject: Re: Confusion of DECIMAL and NUMERIC column types in DB2
PostPosted: Wed Jun 17, 2009 5:42 am 
Newbie

Joined: Wed Jun 17, 2009 5:30 am
Posts: 1
Hi

I am also facing type issue while migrating DB2 from version 8 to version 9.

With DB2Dialect Java type java.util.Calendar is mapped to database column type Date by hibernate without specifying type attribute of the property in hibernate mapping when using DB2 v8.x.

But with v9.x this doesn't work and thowing below exception

com.ibm.db2.jcc.a.SqlException: The value of input host variable or parameter number "11" cannot be used because of its data type.
at com.ibm.db2.jcc.a.kh.c(kh.java:1660)
at com.ibm.db2.jcc.a.kh.a(kh.java:1224)
at com.ibm.db2.jcc.c.db.n(db.java:737)
at com.ibm.db2.jcc.c.db.i(db.java:257)
at com.ibm.db2.jcc.c.db.c(db.java:53)
at com.ibm.db2.jcc.c.t.c(t.java:46)
at com.ibm.db2.jcc.c.sb.g(sb.java:154)
at com.ibm.db2.jcc.a.kh.o(kh.java:1219)
at com.ibm.db2.jcc.a.lh.d(lh.java:2404)
at com.ibm.db2.jcc.a.lh.T(lh.java:465)
at com.ibm.db2.jcc.a.lh.executeUpdate(lh.java:448)

Any help would be great for me.

Thanks
Aslam


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.