0

i want to use Hiberante without Spring and i have some trobules with packagesToScan... Hibernate can not find my entities. I'm working with tomcat7.

This my configurazion:

    <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>

I tried to move classes from build folder to WebContent/WEB-INF/classes but it doesn't work.

1 Answer 1

2

packagesToScan is a Spring feature.

As far as I remember you cannot configure Hibernate Core (not Hibernate EntityManager) to scan classpath for annotated entities.

So, if using Hibernate Core API (Session/SessionFactory) is a requirement you have to enumerate annotated classes manually (for example, as <mapping class = "..." />).

Otherwise you can switch to Hibernate EntityManager (JPA API, EntityManager/EntityManagerFactory) that supports classpath scanning out of the box.

Sign up to request clarification or add additional context in comments.

1 Comment

I didn't understand you last paragraph. The mapping class is my only choice without Spring? Thank you

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.