Java.lang.ClassCastException: org.hibernate.type.StringType cannot be passed to org.hibernate.type.VersionType

I am developing a database connector to retrieve data from an Oracle database. I used the Hibernate tool included as a plugin in Eclipse to generate Hibernate mapping files because I have many classes and tables to map. However, when I run the application, I 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 may be the property type 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 this, and I would not want to change all types in all hbms if this is not a solution. Anyone can help me please.

Thank you very much in advance, May you have a good day.

+7
source share
5 answers

. , , ...:(

+2

, "". "@Version", String - @Version

+13

  • "" "VARCHAR" (), "" "" "", "" "", like-

    .hbm.xml

    <version name="xyz" type="string">
        <column name="xyz" length="30" not-null="true" />
    </version>
    
  • - .

  • if there is a mismatch between the .hbm.xml file and the POJO class file.

+3
source

No length field on

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

I ran into this problem when working with ancient hibernate3 software.

The solution is this: before hibernate3.5 StringTypewas a child class NullableType.

In sleep 3.6, this connection was terminated.

Thus, it StringTypewas StringTypein NullableTypejust before sleep mode 3.5, and in sleep 3.6 this is no longer the case.

The easiest solution is decades from the future: switch back to sleep mode 3.5.

0
source

All Articles