Hibernate没有带注释的弹簧

时间:2012-04-24 13:55:55

标签: hibernate tomcat annotations

我想在没有Spring的情况下使用Hiberante,而且我有一些关于packagesToScan的小块... Hibernate无法找到我的实体。我正在使用tomcat7。

这是我的配置:

    <hibernate-configuration>
    <session-factory>
        <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
        <property name="hibernate.connection.password">password</property>
        <property name="hibernate.connection.url">jdbc:mysql://localhost/ccc</property>
        <property name="hibernate.connection.username">root</property>
        <property name="hibernate.default_schema">ccc</property>
        <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
        <property name="packagesToScan">com.ccc.db.entity</property>
    </session-factory>
</hibernate-configuration>

我尝试将类从build文件夹移动到WebContent / WEB-INF / classes,但它不起作用。

1 个答案:

答案 0 :(得分:2)

packagesToScan是一个Spring功能。

据我所知,你无法配置Hibernate Core(不是Hibernate EntityManager)来扫描带注释实体的类路径。

因此,如果要求使用Hibernate Core API(Session / SessionFactory),则必须手动枚举带注释的类(例如,<mapping class = "..." />)。

否则,您可以切换到支持类路径扫描的Hibernate EntityManager(JPA API,EntityManager / EntityManagerFactory)。

相关问题