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 HibernateException - Wrong column type Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Object Relational Mapping
Reply Bookmark "HibernateException - Wrong column type" Watch "HibernateException - Wrong column type" New topic
Author

HibernateException - Wrong column type

Craig Dumolien
Greenhorn

Joined: Nov 07, 2005
Posts: 20
I'm getting the following error when deploying my code. I think it is a problem with the mapping, but I don't know what's wrong with it. I've included my mapping file, database create so you know how the table was created, a domain object snipet, and the Hibernate properties I have set. I'm using xdoclet2 to create the mapping file. I'm running this on Weblogic 8.1.6, Windows XP (development environment) and DB2 8.x. I've tried this while using double and Double as the types in the domain object, and I get the same error, except "numeric(15,2)" was replaced with "double". Any ideas what I've done wrong?


error
org.hibernate.HibernateException: Wrong column type: RATE, expected: numeric(15,2)
at org.hibernate.mapping.Table.validateColumns(Table.java:251)
at org.hibernate.cfg.Configuration.validateSchema(Configuration.java:1007)
at org.hibernate.tool.hbm2ddl.SchemaValidator.validate(SchemaValidator.java:116)


mapping
<hibernate-mapping>
<class table="PROJECT_FINANCE_RATE_EMPLOYEE" name="com...FinanceRateEmployee">
<composite-id unsaved-value="none" name="financeRateEmployeeID" class="com...FinanceRateEmployeeID">
<key-property name="costCenter" column="COST_CENTER"/>
<key-property name="effectiveDate" column="EFFECTIVE_DATE" type="date"/>
<key-property name="eptRole" column="EPT_ROLE_ID" type="integer"/>
<key-property name="orgId" column="ORG_ID"/>
</composite-id>
<property name="createdAt" column="CREATED_AT" type="timestamp"/>
<property name="createdBy" column="CREATED_BY"/>
<property name="lastChangedAt" column="LAST_CHANGED_AT" type="timestamp"/>
<property name="lastChangedBy" column="LAST_CHANGED_BY"/>
<property name="rate" scale="2" column="RATE" precision="15" type="big_decimal"/>
</class>
</hibernate-mapping>


database create statement for the table
CREATE TABLE "EPTOWNER"."PROJECT_FINANCE_RATE_EMPLOYEE"
("ORG_ID" VARCHAR(10) NOT NULL,
"COST_CENTER" VARCHAR(10) NOT NULL,
"EPT_ROLE_ID" INTEGER NOT NULL,
"EFFECTIVE_DATE" DATE NOT NULL,
"RATE" DECIMAL(15, 2) NOT NULL,
"CREATED_BY" VARCHAR(8) NOT NULL,
"CREATED_AT" TIMESTAMP NOT NULL DEFAULT CURRENT TIMESTAMP,
"LAST_CHANGED_BY" VARCHAR(8) NOT NULL,
"LAST_CHANGED_AT" TIMESTAMP NOT NULL DEFAULT CURRENT TIMESTAMP
)


domain object snipet
private BigDecimal rate;
/**
* @hibernate.property column="RATE"
* type="big_decimal"
* precision="15"
* scale="2"
* @return rate
*/
public BigDecimal getRate() {
return rate;
}
public void setRate(BigDecimal rate) {
this.rate = rate;
}


hibernate Properties I have set
<prop key="hibernate.dialect">org.hibernate.dialect.DB2Dialect</prop>
<prop key="hibernate.hbm2ddl.auto">validate</prop>
<prop key="hibernate.show_sql">true</prop>
Paras Jain
Ranch Hand

Joined: Feb 26, 2005
Posts: 137
Try using
"RATE" NUMERIC(15, 2) NOT NULL,
instead of
"RATE" DECIMAL(15, 2) NOT NULL,
in table definition

or in the hibernate mapping file and data object use

type="double"

instead of

type="big_decimal"

Because according to Java Persistence with Hibernate book
big_decimal is compatible with NUMERIC type in SQL

Rgds,
Paras


Paras Jain
SCJP 5.0
Craig Dumolien
Greenhorn

Joined: Nov 07, 2005
Posts: 20
I've had our DBA change the data type to NUMERIC, however, with DB2, there is no difference between NUMERIC and DECIMAL. When the table gets created it is still created as DECIMAL. I also had the DBA change the precision to 6 with a scale of 2. So, in the database, the column in question shows as DECIMAL(6,2) currently. I have no changes in functionality after these changes. Also, I tried to set the type as double and Double, before my original post, and I then received the same error, except that instead of "numeric(15,2)" is read as "double". Do you have any other suggestions?
 
 
subject: HibernateException - Wrong column type
 
Threads others viewed
Not able to find the added record in table.
Hibernate Issue
Retereive data by ORDER BY
Auto Generator in composite key
org.hibernate.PropertyAccessException: exception setting property value with CGLIB
developer file tools