spring和hibernate与注释的集成会导致PojoEntityTuplizer

时间:2011-09-10 13:04:38

标签: hibernate spring jpa hibernate-mapping

我该如何解决这个异常? 例外:

     Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in class path resource [com/home/app/database/Hibernate-ctx.xml]: 
        Invocation of init method failed; nested exception is org.hibernate.HibernateException: Unable to instantiate default tuplizer [org.hibernate.tuple.entity.PojoEntityTuplizer]
            at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1420)
            at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519)
            at org.spr......
Caused by: org.hibernate.HibernateException: Unable to instantiate default tuplizer [org.hibernate.tuple.entity.PojoEntityTuplizer]
    at org.hibernate.tuple.entity.EntityTuplizerFactory.constructTuplizer(EntityTuplizerFactory.java:108)
    at org.hibernate.tuple.entity.EntityTuplizerFactory.constructDefaultTuplizer(EntityTuplizerFactory.java:133)

模特课:

@Entity
@Table(name = "LOGIN")
public class UserLogin extends Home implements Serializable {

    private static final long serialVersionUID = 1L;
    private Integer loginID;
    private String loginName;
    private String loginPassword;

    public UserLogin() {
    }

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "LOGIN_ID")
    public Integer getLoginID() {
        return this.loginID;
    }

    @Column(name = "LOGIN_NAME")
    public String getLoginName() {
        return loginName;
    }

    @Column(name = "LOGIN_PASSWORD")
    public String getLoginPassword() {
        return loginPassword;
    }

它是相应的setter方法。

spring上下文件:

 <context:annotation-config />
      <context:component-scan base-package="com.home.app" />
      <bean id="sessionFactory" 
            class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">        
                    <property name="dataSource">
                        <ref bean="dataSource" />
                    </property>

...

    <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
            <property name="driverClassName" value="${jdbc.driverClassName}" />
            <property name="url" value="${jdbc.url}" />
            <property name="username" value="${jdbc.username}" />
            <property name="password" value="${jdbc.password}" />
        </bean>

在mysql中查询:

CREATE TABLE LOGIN
(
LOGIN_NAME varchar(255),
LOGIN_PASSWORD varchar(255),
LOGIN_ID int(11) not null
);

DAO课程:

public class LoginDetailsDAOImpl implements LoginDetailsDAO {
    HibernateTemplate hibernateTemplate;

    public void setSessionFactory(SessionFactory sessionFactory)  {
        this.hibernateTemplate = new HibernateTemplate(sessionFactory);
    }

    @Transactional(readOnly = true)
    public List<UserLogin> loginDetails(UserLogin login) {

        return hibernateTemplate.find("from Login");
    }
}

1 个答案:

答案 0 :(得分:4)

下载将Javaassist jar添加到您的类路径并测试它。

Maven依赖:

<dependency>
    <groupId>javassist</groupId>
    <artifactId>javassist</artifactId>
    <version>3.12.1.GA</version>
</dependency>