Software Development

Reuse JPA entity classes from a Jar file

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:

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.

[wp_ad_camp_3]

Loading

Got comments or suggestions? We disabled the comments on this site to fight off spammers, but you can still contact us via our Facebook page!.


You Might Also Like