-->
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.  [ 9 posts ] 
Author Message
 Post subject: Wrong column type: STATUS, expected: varchar2(2)
PostPosted: Fri Feb 24, 2006 10:10 am 
Newbie

Joined: Thu Apr 14, 2005 9:38 am
Posts: 17
Hey all,

I'm pretty new to hibernate. I'm trying to learn it to make my life easier. I'm running into a problem though.

I'm using the reverse engineering of the JBoss IDE on one of our databases that we have in production. Some of the tables use a column type of CHAR(2). This is the exception I'm getting.

Problem while executing Create SessionFactory(org.hibernate.HibernateException: Wrong column type: STATUS, expected: varchar2(2))

Can anyone tell me how to fix this? Why doesn't hibernate support fixed length columns? Or is there something I'm doing wrong?

One odd thing is that it was working at one point. I reverse engineered it once and it worked. Then I made a few changes to the reverse engineering and then re-ran it and then it gave me that error. The changes I made had nothing to do with that table. All I did was add another table to reverse engineering. I've since removed all tables accept this one and it still doesn't work like it did before.



















Hibernate version:

Hibernate3, with hibernate tools beta4

Mapping documents:

<hibernate-mapping>
<class name="com.thestar.om.db.Page" table="PAGE">
<id name="id" type="big_decimal">
<column name="ID" precision="20" scale="0" />
<generator class="assigned" />
</id>
<property name="createdby" type="string">
<column name="CREATEDBY" length="64" not-null="true" />
</property>
<property name="category" type="string">
<column name="CATEGORY" length="4" />
</property>
<property name="description" type="string">
<column name="DESCRIPTION" length="128" />
</property>
<property name="template" type="string">
<column name="TEMPLATE" length="32" />
</property>
<property name="subtype" type="string">
<column name="SUBTYPE" length="24" />
</property>
<property name="workflowid" type="string">
<column name="WORKFLOWID" length="16" />
</property>
<property name="createddate" type="timestamp">
<column name="CREATEDDATE" length="7" not-null="true" />
</property>
<property name="updatedby" type="string">
<column name="UPDATEDBY" length="64" not-null="true" />
</property>
<property name="status" type="string">
<column name="STATUS" length="2" not-null="true" />
</property>
<property name="startdate" type="timestamp">
<column name="STARTDATE" length="7" />
</property>
<property name="name" type="string">
<column name="NAME" length="32" not-null="true" unique="true" />
</property>
<property name="enddate" type="timestamp">
<column name="ENDDATE" length="7" />
</property>
<property name="updateddate" type="timestamp">
<column name="UPDATEDDATE" length="7" not-null="true" />
</property>
<property name="filename" type="string">
<column name="FILENAME" length="64" />
</property>
<property name="path" type="string">
<column name="PATH" />
</property>
</class>
</hibernate-mapping>

Full stack trace of any exception that occurs:

org.hibernate.HibernateException: Wrong column type: STATUS, expected: varchar2(2)
at org.hibernate.mapping.Table.validateColumns(Table.java:219)
at org.hibernate.cfg.Configuration.validateSchema(Configuration.java:964)
at org.hibernate.tool.hbm2ddl.SchemaValidator.validate(SchemaValidator.java:116)
at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:296)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1154)
at org.hibernate.console.ConsoleConfiguration$2.execute(ConsoleConfiguration.java:265)
at org.hibernate.console.execution.DefaultExecutionContext.execute(DefaultExecutionContext.java:35)
at org.hibernate.console.ConsoleConfiguration.execute(ConsoleConfiguration.java:68)
at org.hibernate.console.ConsoleConfiguration.buildSessionFactory(ConsoleConfiguration.java:260)
at org.hibernate.eclipse.console.actions.BuildSessionFactoryAction.doRun(BuildSessionFactoryAction.java:38)
at org.hibernate.eclipse.console.actions.ConsoleConfigurationBasedAction.run(ConsoleConfigurationBasedAction.java:46)
at org.eclipse.ui.actions.BaseSelectionListenerAction.runWithEvent(BaseSelectionListenerAction.java:167)
at org.eclipse.jface.action.ActionContributionItem.handleWidgetSelection(ActionContributionItem.java:538)
at org.eclipse.jface.action.ActionContributionItem.access$2(ActionContributionItem.java:488)
at org.eclipse.jface.action.ActionContributionItem$5.handleEvent(ActionContributionItem.java:400)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:66)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:843)
at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:3080)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:2713)
at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:1699)
at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:1663)
at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:367)
at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:143)
at org.eclipse.ui.internal.ide.IDEApplication.run(IDEApplication.java:103)
at org.eclipse.core.internal.runtime.PlatformActivator$1.run(PlatformActivator.java:226)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:376)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:163)
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.eclipse.core.launcher.Main.invokeFramework(Main.java:334)
at org.eclipse.core.launcher.Main.basicRun(Main.java:278)
at org.eclipse.core.launcher.Main.run(Main.java:973)
at org.eclipse.core.launcher.Main.main(Main.java:948)

Name and version of the database you are using:

Oracle 8.1.4


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 24, 2006 10:15 am 
Beginner
Beginner

Joined: Wed Aug 04, 2004 4:33 am
Posts: 45
Location: Switzerland
Hibernate supports fixed column length but as you say your columns in the database are of type CHAR(2) whereas hibernate mapps String to VARCHAR2(2).


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 24, 2006 10:19 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
why are you running the schemavalidator ?

and for some reason it thinks STATUS has been used as a type...how does your reveng.xml look like ?

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 24, 2006 10:27 am 
Newbie

Joined: Thu Apr 14, 2005 9:38 am
Posts: 17
I've removed the schema validator and it works.

Why is it that the validator causes the Session Factory to fail? CHAR is still a valid data type.

Thank you,


Steve.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 24, 2006 10:41 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
that is why i wanted to know what your reveng.xml file looks like...and somewhere STATUS must be listed as a type isntead of char2

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 24, 2006 10:44 am 
Newbie

Joined: Thu Apr 14, 2005 9:38 am
Posts: 17
There's really nothing special in my reveng.xml file. Here is the table def for PAGE.

<table name="PAGE"></table>


It finds everything on it's own.

Thank you,


Steve.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 24, 2006 10:49 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
and why should the table mapping be interesting ?

i want the type-mapping and also would like to know if those mapping files are the only ones being used when the error occurs.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 24, 2006 10:58 am 
Newbie

Joined: Thu Apr 14, 2005 9:38 am
Posts: 17
There are no type mappings. I'm pretty new to this. I'm not quite sure what the type mapping is for yet so I haven't set anything int the type mapping.

Here is the whole reveng.xml file.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-reverse-engineering PUBLIC "-//Hibernate/Hibernate Reverse Engineering DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-reverse-engineering-3.0.dtd" >

<hibernate-reverse-engineering>
<table-filter match-name="PAGE" />
<table-filter match-name=".*" exclude="true" />
<table name="PAGE"></table>
</hibernate-reverse-engineering>


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 06, 2006 11:11 am 
Newbie

Joined: Fri Mar 03, 2006 2:11 pm
Posts: 16
Please see this link. I had same problem:

http://forum.hibernate.org/viewtopic.ph ... highlight=

Please see last entry which solved my problem. In mapping file if you can make changes link this:

from your ref:

<property name="status" type="string">
<column name="STATUS" length="2" not-null="true" />
</property>

change to:
<property name="status" type="string">
<column name="STATUS" sql-type ="char" length="2" not-null="true" />
</property>

This should solve you problem. By default Hibernate assumes that the column is string and compares against VARCHAR(255). This problem happens only when schema is validated. For any other cases this problem will not arise

Best wishes. If this is helpful please rate it. Thank you. Hari


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 9 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.