Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Playframework : How to share models between different projects?

I want to share my Models with some other projects, they use the same models but not the same field mappings and constraints. I wonder if there is way to extract annotations from models and use xml configuration instead ? Or other way to achieve this ?

NOTE : I'm using play 1.3.

like image 970
WoooHaaaa Avatar asked Nov 24 '25 06:11

WoooHaaaa


1 Answers

Last week I were analyzing something like that.

A way to archive this is:

  1. generate a library (jar) for each reusable models, defined by annotations or by orm.xml files on META-INF folder (but not presistence.xml).
  2. In web application project, reference required model libraries and define the entityManager using a persistence.xml on META-INF.

For more information see the JPA spec, 6.2 Persistence Unit Packaging

Other references:

  • JPA - multiple jars defining @Entity objects
  • JPA 2.0: Adding entity classes to PersistenceUnit *from different jar* automatically
  • https://www.java.net/node/665328

Good luck!

like image 59
jmvivo Avatar answered Nov 25 '25 20:11

jmvivo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!