How To Fix “Unable to instantiate default tuplizer [org.hibernate.tuple.entity.PojoEntityTuplizer]”

When I worked with my project wich using Hibernate + SpringMVC, I got this kind of error when I run my project:

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 'sampleController': 
Injection of autowired dependencies failed; 
nested exception is org.springframework.beans.factory.BeanCreationException:
Could not autowire field: 
private com.ariestania.sample.service.LogUserActionService com.ariestania.sample.controller.BaseController.logUserActionService; 
nested exception is org.springframework.beans.factory.BeanCreationException: 
Error creating bean with name 'logUserActionService': 
Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: 
Could not autowire field: 
private org.hibernate.SessionFactory com.ariestania.sampleservice.LogUserActionService.sessionFactory; nested exception is org.springframework.beans.factory.BeanCreationException: 
Error creating bean with name 'sessionFactory' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: 
Invocation of init method failed; nested exception is org.hibernate.HibernateException: Unable to instantiate default tuplizer [org.hibernate.tuple.entity.PojoEntityTuplizer]

I though that error occured because  there is something wrong with my applicationcontext. But it looks fine for me.

    <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager"
          p:sessionFactory-ref="sessionFactory"/>

That kind of error happened because my model class has typo. So what I need is just a little text correction on my model class. Another things that can occure that error are:

  1. No getter or setter. Make sure all variable that represent your table has getter and setter. Check the text too. Don’t make typo like what I did 😀
  2. Different name on xml mapping file and model class. If you use xml file to mapping your table, make sure variable name are correct. Example :
    <?xml version="1.0"?>
    <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
    "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
    <hibernate-mapping>
        <class name="com.ariestania.sample.model.LogUserAction" table="LOG_USER_ACTION" schema="SAMPLE">
            <composite-id name="id" class="com.ariestania.sample.model.LogUserActionId">
                <key-property name="actionTime" type="timestamp">
                    <column name="ACTION_TIME" length="7" />
                </key-property>
                <key-property name="actionUser" type="string">
                    <column name="ACTION_USER" length="40" />
                </key-property>
            </composite-id>
            <property name="actionType" type="string">
                <column name="ACTION_TYPE" length="200" not-null="true" />
            </property>
        </class>
    </hibernate-mapping>
    

    name=”actionType” on the property tag means your varible name on your model class is actionType which is represent ACTION_TYPE column. If you use composite key for your table and represent it into a class, make sure the class name is correct.

    public class LogUserAction  implements java.io.Serializable {
    
         private LogUserActionId id;
         private String actionType;
    
        public LogUserAction() {
        }
    
        public LogUserAction(LogUserActionId id, String actionType) {
           this.id = id;
           this.actionType = actionType;
        }
       
        public LogUserActionId getId() {
            return this.id;
        }
        
        public void setId(LogUserActionId id) {
            this.id = id;
        }
        public String getActionType() {
            return this.actionType;
        }
        
        public void setActionType(String actionType) {
            this.actionType = actionType;
        }
    }
    
    public class LogUserActionId  implements java.io.Serializable {
    
         private Date actionTime;
         private String actionUser;
    
        public LogUserActionId() {
        }
    
        public LogUserActionId(Date actionTime, String actionUser) {
           this.actionTime = actionTime;
           this.actionUser = actionUser;
        }
       
        public Date getActionTime() {
            return this.actionTime;
        }
        
        public void setActionTime(Date actionTime) {
            this.actionTime = actionTime;
        }
        public String getActionUser() {
            return this.actionUser;
        }
        
        public void setActionUser(String actionUser) {
            this.actionUser = actionUser;
        }
    
    }
    

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s