Background
[wp_ad_camp_1]
Let’s say you had your application in one single Maven project as a prototype and decided to finalize the functionality into a finished (or almost, e.g., Alpha or Beta version) product. When you have JPA entities and you separated them into a single jar file, your persistence.xml needs to change and use the <class> tag in that file.
Of course, the JPA entities jar file has to be in the classpath.
Software Environment
- Windows 7 Professional SP1
- Eclipse – Kepler Release
- Java 1.7 (1.7.0_67 – Windows x86)
- MySQL 5.6.16 – Community Server (GPL)
- MySQL Java Connector 5.1.34
- Hibernate 4.3.7 (Entity Manager)
JPA Entity Class
[wp_ad_camp_2]
Your entities can keep their JPA-related annotations. Here is a sample entity class:
1 2 3 4 5 6 7 8 9 10 11 12 13 | @Entity @Table(name = "PERSON") public class Person implements Serializable { private static final long serialVersionUID = 1L; @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(name = "PERSON_ID") private Integer personId; @Column(name = "PERSON_NAME") private String personName; } |
Modify persistence.xml
Although your classes may be in a separate jar file, they are still in the same application and it referenced in persistence.xml using <class> tags.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | <?xml version="1.0" encoding="UTF-8"?> <persistence version="2.0" 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"> <persistence-unit name="TurretaPersistenceUnit" transaction-type="RESOURCE_LOCAL"> <provider>org.hibernate.ejb.HibernatePersistence</provider> <class>com.turreta.domain.Person</class> <properties> <property name="hibernate.dialect" value="org.hibernate.dialect.Oracle10gDialect"/> <property name="hibernate.show_sql" value="true"/> <property name="hibernate.cache.use_query_cache" value="false"/> <property name="hibernate.cache.use_second_level_cache" value="true"/> <property name="hibernate.cache.provider_class" value="org.hibernate.cache.EhCacheProvider"/> </properties> </persistence-unit> </persistence> |
[wp_ad_camp_3]