8

I am developing a database connector in order to retrieve data from a Oracle database. I have used the Hibernate tool included as a plug-in in Eclipse for the generation of the Hibernate mapping files because I have a lot of classes and tables to map. However, when I run the application, I have just get the following Exception:

java.lang.ClassCastException: org.hibernate.type.StringType cannot be cast to org.hibernate.type.VersionType
    at org.hibernate.tuple.PropertyFactory.buildVersionProperty(PropertyFactory.java:107)
    at org.hibernate.tuple.entity.EntityMetamodel.<init>(EntityMetamodel.java:181)
    at org.hibernate.persister.entity.AbstractEntityPersister.<init>(AbstractEntityPersister.java:485)
    at org.hibernate.persister.entity.SingleTableEntityPersister.<init>(SingleTableEntityPersister.java:133)
    at org.hibernate.persister.PersisterFactory.createClassPersister(PersisterFactory.java:84)
    at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:286)
    at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1845)
    at eu.cartif.dwhconn.database.DBManager.checkDWHStatus(DBManager.java:57)
    at eu.cartif.dwhconn.database.DBManager.main(DBManager.java:24)

I think the problem could be the type of the property of the hbm file:

<hibernate-mapping>
<class name="eu.cartif.dwhconn.database.Ifcactorrole" table="IFCACTORROLE">
    <id name="role" type="string">
        <column name="ROLE" length="50" />
        <generator class="assigned" />
    </id>
    <property name="userdefinedrole" type="string">
        <column name="USERDEFINEDROLE" />
    </property>
    <property name="description" type="string">
        <column name="DESCRIPTION" length="3000" />
    </property>
    <set name="ifcpersons" table="IFCPERSON" inverse="true" lazy="true" fetch="select">
        <key>
            <column name="ROLES" length="50" />
        </key>
        <one-to-many class="eu.cartif.dwhconn.database.Ifcperson" />
    </set>
    <set name="ifcpersonandorganizations" table="IFCPERSONANDORGANIZATION" inverse="true" lazy="true" fetch="select">
        <key>
            <column name="ROLES" length="50" />
        </key>
        <one-to-many class="eu.cartif.dwhconn.database.Ifcpersonandorganization" />
    </set>
</class>
</hibernate-mapping>

However, I am not sure about it and I would not like to change all the types in all the hbms if that is not the solution. Anyone could help me, please.

Thank you very much in advance, May you have a nice day

4
  • Are you sure this is the class which causes that exception? What about the mapping files for the other entities? Do you use a version somewhere or a property named version? Commented Feb 28, 2013 at 10:47
  • I was searching for any property or field called "version". However the only one found out was <?xml version="1.0"?> Commented Feb 28, 2013 at 10:56
  • Are you using annotations as well? Does the class contain a field with that name? Commented Feb 28, 2013 at 11:13
  • I am not using annotations neither a field with the name "version" :-( Commented Feb 28, 2013 at 11:26

5 Answers 5

17

In my case, I generated entity from DB and some entities column name has "version". Generator for this names add "@Version" annotation, but this column type is String - for @Version annotation unacceptable

Sign up to request clarification or add additional context in comments.

Comments

3

This types of problem occurs

  • if there are column name as "version" of "VARCHAR" (string) type in any table, means in hibernate "property" becomes "version" and "type" becomes "string", like-

    in .hbm.xml file

    <version name="xyz" type="string">
        <column name="xyz" length="30" not-null="true" />
    </version>
    
  • if there are any missing getter or setter method for a particular attribute.

  • if there are mismatch between .hbm.xml file and POJO class file.

Comments

2

I have checked several times all the mapping classes. Finally, the problem came from a mapping class which had not the proper type for an attribute... :( Thank you for your responses

Comments

0

Missing length field on

<property name="userdefinedrole" type="string">
    <column name="USERDEFINEDROLE" />
</property>

1 Comment

I think the length does not matter because in the java classes the property is a String without the length and the problem is about casting. However I tried your solution and it does not work.
0

I faced this problem with working on an ancient, hibernate3 software.

The solution is this: until hibernate3.5, StringType was a child class of NullableType.

In hibernate 3.6, this relation was ended.

Thus, StringType was convertable to a NullableType only until hibernate 3.5, from hibernate 3.6 it is not so any more.

The simplest solution is, now decades away from the future: switch back to hibernate 3.5.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.