Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I would suggest configuring your test persistence unit programmatically to avoid multiple persistence.xml's or multiple persistence units. This case is made a bit more complicated by the multiple schemas requirement as it involves mapping file overrides. Standard properties are easy to pass in when creating an EntityManagerFactory, but this case would require the use of a <a href="http://static.springsource.org/spring/docs/3.0.x/javadoc-api/org/springframework/orm/jpa/persistenceunit/PersistenceUnitPostProcessor.html" rel="nofollow noreferrer">PersistenceUnitPostProcessor</a> using the <a href="http://static.springsource.org/spring/docs/3.0.x/javadoc-api/org/springframework/orm/jpa/persistenceunit/MutablePersistenceUnitInfo.html" rel="nofollow noreferrer">MutablePersistenceUnitInfo</a> to add the mapping file references.</p> <p>Take a look at <a href="https://stackoverflow.com/questions/2838634/programmatically-loading-entity-classes-with-jpa-2-0">Programmatically loading Entity classes with JPA 2.0?</a> for a good example of how you would configure this. The API on <a href="http://static.springsource.org/spring/docs/3.0.x/javadoc-api/org/springframework/orm/jpa/persistenceunit/MutablePersistenceUnitInfo.html" rel="nofollow noreferrer">MutablePersistenceUnitInfo</a> will allow you to add the mapping file refs. As for the class refs, you would be getting this automatically from the original persistence.xml which you are modifying in the post processing (in the test config only), which solves the duplication problem.</p> <p>So, maybe you could end up with a PersistenceUnitPostProcessor like this:</p> <pre><code>public class ConfigureTestMappingFiles implements PersistenceUnitPostProcessor { private List&lt;String&gt; mappingFiles; @Override public void postProcessPersistenceUnitInfo(MutablePersistenceUnitInfo pui) { if (mappingFiles != null) { pui.getMappingFileNames().addAll(mappingFiles); } } // ... getter and setter for mappingFiles } </code></pre> <p>and, in your configuration you would register it like this:</p> <pre><code>&lt;bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean" depends-on="hsqlFixes"&gt; &lt;property name="persistenceUnitName" value="programasPlanosEnsino" /&gt; &lt;property name="persistenceXmlLocation" value="META-INF/persistence.xml" /&gt; ... &lt;property name="persistenceUnitPostProcessors"&gt; &lt;list&gt; &lt;bean class="com.example.test.ConfigureTestMappingFiles"&gt; &lt;property name="mappingFiles"&gt; &lt;list&gt; &lt;value&gt;META-INF/orm-tests-db1.xml&lt;/value&gt; &lt;value&gt;META-INF/orm-tests-db2.xml&lt;/value&gt; ... add more as needed &lt;/list&gt; &lt;/property&gt; &lt;/bean&gt; &lt;/list&gt; &lt;/property&gt; </code></pre> <p>Hope this helps.</p>
 

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