Hibernate 3.6 sessionFactory.getAllClassMetadata()为空

时间:2013-01-13 13:05:15

标签: hibernate persistence seam

我已经设置了几个实体,例如

@Entity
@Table
public class Question implements Serializable {

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;

    private String question;

    @OneToMany(mappedBy = "question", fetch = FetchType.EAGER)
    private List<Answer> answers = new ArrayList<>();

    //getter, setter, custom methods
}

的components.xml

    [...]

    <persistence:hibernate-session-factory name="sessionFactory"/>
    <persistence:managed-hibernate-session name="session"
                                           session-factory="#{sessionFactory}"/>
    [...]

的persistence.xml

<?xml version="1.0" encoding="UTF-8"?>
<!-- Persistence deployment descriptor for dev profile -->
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
             version="2.0">

    <persistence-unit name="seam_helloworld" transaction-type="JTA">
        <provider>org.hibernate.ejb.HibernatePersistence</provider>
        <jta-data-source>java:/firstjsf</jta-data-source>
        <properties>
            <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/>
            <property name="hibernate.hbm2ddl.auto" value="update"/>
            <property name="hibernate.show_sql" value="true"/>
            <property name="hibernate.format_sql" value="true"/>
            <property name="jboss.entity.manager.factory.jndi.name" value="java:/seam_helloworldEntityManagerFactory"/>
            <property name="hibernate.connection.useUnicode" value="true"/>
            <property name="hibernate.connection.characterEncoding" value="UTF-8"/>
            <property name="jboss.as.jpa.providerModule" value="org.hibernate:3"/>
        </properties>
    </persistence-unit>

</persistence>

当我调用sessionFactory.getAllClassMetadata()时,我得到的是一个零大小的映射,类似于sessionFactory.getClassMetadata(Question.class)返回null。

我该如何解决这个问题?我使用Hibernate 3.6,Seam 2.3,JBoss AS 7.1.1

1 个答案:

答案 0 :(得分:0)

尝试在persistence.xml中包含Question和Answer类