Reputation: 1298
I am using persistence.xml
to specify my mapping setting in Hibernate. That is I am using the EntityManager class to get my transactions.
Now I have the following classes listed in my persistence.xml
<class>test.entity.Course</class>
<class>test.entity.Semester</class>
<class>test.entity.Subject</class>
Also in my Eclipse project I have two more classes (Student.java and User.java) that are marked with the @Entity
annotation but are not listed in the persistence.xml
file.
But when I run my project Hibernate actually maps those two classes as well. What I mean is that it creates database tables for those two classes as well (I have hbm2ddl
set to auto
).
Why is it doing this ? Isn't it suppose to map only the files listed in persistence.xml
?
Upvotes: 3
Views: 1452
Reputation: 7695
By default, JPA standard states, that in application server environment, all classes annotated with @Entity are considered, whether they are listed in persistence.xml or not. If you really want to include only those 3 entities mentioned in persistence.xml, you need to add following setting into your persistence.xml file into the persistence-unit element:
<exclude-unlisted-classes>true</exclude-unlisted-classes>
Upvotes: 3
Reputation: 994
Hibernate can be configured with either persistence.xml or with JPA annotations.
Upvotes: -1