I am pretty sure that I used some sort of auto detection of beans annotated with @Entity in JPA 2.0 in the past but I am not able to find out how. How do you do that instead of listing each bean in a class
XML element in the persistence.xml?
Since Spring 3.1, you also have the option to forget persistence.xml altogether, and configure your EntityManagerFactory
using the packagesToScan
property, similar to this:
<bean id="entityManagerFactory"
class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"
p:dataSource-ref="dataSource"
p:packagesToScan="${jpa.entity.packages}">
<property name="jpaVendorAdapter">
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"
p:showSql="${hibernate.show_sql}"/>
</property>
<property name="jpaProperties">
<props>
<prop key="hibernate.format_sql">${hibernate.format_sql}</prop>
<prop key="hibernate.hbm2ddl.auto">${hibernate.hbm2ddl.auto}</prop>
</props>
</property>
</bean>
You need add to the persistence.xml
the next line:
<exclude-unlisted-classes>false</exclude-unlisted-classes>
e.g.
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0" ...>
<persistence-unit name="YourPU" ...>
<exclude-unlisted-classes>false</exclude-unlisted-classes>
<properties>
<property name="eclipselink.logging.level" value="ALL"/>
<property name="eclipselink.ddl-generation"
value="drop-and-create-tables"/>
</properties>
</persistence-unit>
</persistence>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With