Problem Faced in Hibernate

Here i will add all the problem related to Hibernate which i have faced while developing the Application in Hibernate.

Problem Type: java.lang.ClassCastException: org.hibernate.type.StringType cannot be cast to org.hibernate.type.VersionType

Problem In: Hibernate Tool While reverse engineering

Reason for this problem: In one of my table there was a field named version. Which Hibernate tool treated as field version and try to cast the same and it throws an exception becasue the type of the field was not what hibernate tool was expecting.

Resolution: Open the hbm configuration file for corresponding table and change the configuration of that field from <version> to <property> .

Other Detail:  More details could be found here

—————————————————————————————-

Difference between

<property name=”hibernate.show.sql”>true</property>  &

<property name=”show_sql”>true</property>

Second one is displaying the query while first one is not displaying query in console.

Why Hibernate is not working properly if default schema is provided explicitly

If  default schema is provided in connection URL and explicitly then it cause problem inn Hibernate

<property name=”hibernate.connection.url”>jdbc:mysql://localhost/abc</property>

<property name=”hibernate.default_schema”>abc</property>

—————————————

Problems: If using Hibernate Tools and there is two tables with same name only difference is for number or special character(ABC & ABC1 & ABC_) then tool will throw error saying the generated classes are same for theses tables.

Resolution: Manual class creation can be done. To exclude given Tables while creating mapping and class file reveng.xml file can be used.

 

0 Comments Problem Faced in Hibernate

  1. Brighton

    Hello, thanks for the post. I had a similar problem and indeed in my database I had a field called version. I have renamed the field name to license_version but and run the reverse engineering tool again. However I am still failing to start the application from Spring. Here is the error I am getting. Any suggestions are welcome:

    “Severe: Exception while loading the app : java.lang.IllegalStateException: ContainerBase.addChild: start: org.apache.catalina.LifecycleException: org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘settingsController’: Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: com.zelper.hrm.services.ChangePasswordService com.zelper.hrm.controller.SettingsController.changePasswordService; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘changePasswordService’: Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.zelper.hrm.dao.RaUsersDao com.zelper.hrm.services.ChangePasswordServiceImpl.raUsersDao; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘raUsersDaoImpl’: Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.zelper.hrm.dao.HibernateUtil com.zelper.hrm.dao.GenericDaoImpl.hibernateUtilDao; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘hibernateUtil’: Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.hibernate.SessionFactory com.zelper.hrm.dao.HibernateUtil.sessionFactory; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘ZelperHRMFactory’ defined in class com.zelper.hrm.springconfig.SpringWebConfig: Instantiation of bean failed; nested exception is org.springframework.beans.factory.BeanDefinitionStoreException: Factory method [public org.hibernate.SessionFactory com.zelper.hrm.springconfig.SpringWebConfig.sessionFactory()] threw exception; nested exception is org.hibernate.MappingException: Could not instantiate persister org.hibernate.persister.entity.SingleTableEntityPersister”

    Reply

Leave A Comment

Your email address will not be published. Required fields are marked *