Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hibernate Initial SessionFactory creation failed

I'm trying to use hibernate to fill my jsf selectonemenu in ApplicationBean (in Liferay). The problem is that I got Initial SessionFactory creation failed problem. Before putting my functions in the applicationbean I was setting them in sessionbean and I got no error.

For now the full error

Initial SessionFactory creation failed. 
java.lang.ClassCastException: org.hibernate.type.StringType cannot be cast to org.hibernate.type.VersionType
like image 872
Feras Odeh Avatar asked Jan 21 '23 22:01

Feras Odeh


2 Answers

You have very likely a VARCHAR column called VERSION somewhere and Hibernate's reverse engineering tool generates it as:

<version name="version" type="string">
    <column name="VERSION" length="20" />
</version>

instead of:

<property name="version" type="string">
    <column name="VERSION" length="20" />
</property>

The former is wrong. First, I think that this is not what you want. Second, a string is not allowed for a version field as mentioned in the chapter 5.1.9. Version (optional):

Version numbers can be of Hibernate type long, integer, short, timestamp or calendar.

This problem has been somehow reported in HHH-3002 (actually, it should be assigned to Hibernate Tools, not Hibernate Core) and I see two ways to solve it. Either

  • fix the mapping manually
  • rename the column to something else.
like image 125
Pascal Thivent Avatar answered Jan 26 '23 10:01

Pascal Thivent


The property on one of your domain classes that you've mapped as the class's version is of type string. This is not a valid type for a version. What to change it to will depend on how you are implementing versioning in your underlying database.

like image 34
David M Avatar answered Jan 26 '23 09:01

David M