Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>JPA doesn't offer this feature yet. Here are three options you can check out :</p> <ul> <li><p><a href="https://stackoverflow.com/q/2838634/363573">Programmatically loading Entity classes with JPA 2.0?</a><br> This question on SO is similar to yours. An answer reports that it feasible with Spring.<br><br></p></li> <li><p><a href="https://stackoverflow.com/q/6380728/363573">JPA 2.0: Adding entity classes to PersistenceUnit *from different jar* automatically</a><br> Good pointers are given here.<br><br></p></li> <li><p>Last but not least, a simple work around :<br> <strong>1.</strong> Generate a <code>persistence.xml</code> on the fly (simple XML file creation) with a new persistence unit.<br> <strong>2.</strong> Add persistence file to classpath dynamically (<code>URLCLassLoader</code>)<br> <strong>3.</strong> Ask <code>PersistenceProvider</code> to load new persistence unit (<code>createEntityManagerFactory</code>)</p></li> </ul> <p><strong>EDIT:</strong></p> <p>If the JPA provider is Hibernate, since Hibernate 4.0, it's possible to pass directly entities to this JPA provider <strong>without declaring them</strong> in the <code>persistence.xml</code> file. Hibernate will handle the entities on the fly.</p> <p><strong>EDIT:</strong></p> <p>Here is a sample configuration of JPA 2.1 + Hibernate 4.3.7.Final without declaring any entities :</p> <p><strong>META-INF/persistence.xml</strong></p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8" ?&gt; &lt;persistence xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd" version="2.1"&gt; &lt;persistence-unit name="my-persistence-unit" transaction-type="RESOURCE_LOCAL"&gt; &lt;provider&gt;org.hibernate.jpa.HibernatePersistenceProvider&lt;/provider&gt; &lt;properties&gt; &lt;!-- Database Properties --&gt; &lt;property name="javax.persistence.jdbc.url" value="jdbc:postgresql://localhost:5432/my-database" /&gt; &lt;property name="javax.persistence.jdbc.user" value="login" /&gt; &lt;property name="javax.persistence.jdbc.password" value="password" /&gt; &lt;!-- Hibernate Properties --&gt; &lt;property name="hibernate.connection.driver_class" value="org.postgresql.Driver" /&gt; &lt;property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect" /&gt; &lt;property name="hibernate.default_schema" value="public" /&gt; &lt;property name="hibernate.hbm2ddl.auto" value="update" /&gt; &lt;property name="hibernate.show_sql" value="false" /&gt; &lt;property name="hibernate.format_sql" value="true" /&gt; &lt;!-- Connection Pool --&gt; &lt;property name="hibernate.c3p0.min_size" value="5" /&gt; &lt;property name="hibernate.c3p0.max_size" value="20" /&gt; &lt;property name="hibernate.c3p0.timeout" value="500" /&gt; &lt;property name="hibernate.c3p0.max_statements" value="50" /&gt; &lt;property name="hibernate.c3p0.idle_test_period" value="2000" /&gt; &lt;/properties&gt; &lt;/persistence-unit&gt; &lt;/persistence&gt; </code></pre> <p><strong>References</strong></p> <ul> <li><a href="http://download.oracle.com/otndocs/jcp/persistence-2_1-fr-eval-spec/index.html" rel="nofollow noreferrer">JPA 2.1 Specs : 8.2 Persistence Unit Packaging</a></li> <li><a href="http://download.oracle.com/otndocs/jcp/persistence-2_1-fr-eval-spec/index.html" rel="nofollow noreferrer">JPA 2.1 Specs : 8.2.1.6 mapping-file, jar-file, class, exclude-unlisted-classes</a></li> </ul>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload