Test persistence.xml

Hi!
I have a project that has a dependency on an external application component. I am using an entity from the external component as an association dependency with an entity in my application. So the setup is:

Name of my app = cares
Name of app component = rda

The persistence.xml from the “core” folder of the app is listed below:

    <?xml version="1.0" encoding="UTF-8" standalone="no"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
             version="2.0">
    <persistence-unit name="cares"
                      transaction-type="RESOURCE_LOCAL">
        <class>com.non.cares.entity.Person</class>
        <class>com.non.cares.entity.IncidentReport</class>
        <class>com.non.cares.entity.Allegation</class>
        <class>com.non.cares.entity.Victim</class>
        <class>com.non.cares.entity.Reporter</class>
        <class>com.non.cares.entity.Perpetrator</class>
    </persistence-unit>
</persistence>

The persistence.xml file from the test-home/cuba/work folder is as follows:

<?xml version="1.0" encoding="UTF-8"?>

<persistence xmlns="http://java.sun.com/xml/ns/persistence" version="2.0">
  <persistence-unit name="cares" transaction-type="RESOURCE_LOCAL">
    <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
    <class>com.haulmont.cuba.core.entity.BaseGenericIdEntity</class>
    <class>com.haulmont.cuba.core.entity.BaseUuidEntity</class>
    <class>com.haulmont.cuba.core.entity.BaseLongIdEntity</class>
    <class>com.haulmont.cuba.core.entity.BaseIntegerIdEntity</class>
    <class>com.haulmont.cuba.core.entity.BaseStringIdEntity</class>
    <class>com.haulmont.cuba.core.entity.BaseDbGeneratedIdEntity</class>
    <class>com.haulmont.cuba.core.entity.BaseIdentityIdEntity</class>
    <class>com.haulmont.cuba.core.entity.BaseIntIdentityIdEntity</class>
    <class>com.haulmont.cuba.core.entity.StandardEntity</class>
    <class>com.haulmont.cuba.core.entity.EmbeddableEntity</class>
    <class>com.haulmont.cuba.core.entity.Server</class>
    <class>com.haulmont.cuba.core.entity.Config</class>
    <class>com.haulmont.cuba.core.entity.FileDescriptor</class>
    <class>com.haulmont.cuba.core.entity.LockDescriptor</class>
    <class>com.haulmont.cuba.core.entity.Folder</class>
    <class>com.haulmont.cuba.core.entity.AbstractSearchFolder</class>
    <class>com.haulmont.cuba.core.entity.AppFolder</class>
    <class>com.haulmont.cuba.core.entity.FtsQueue</class>
    <class>com.haulmont.cuba.core.entity.EntityStatistics</class>
    <class>com.haulmont.cuba.core.entity.SendingMessage</class>
    <class>com.haulmont.cuba.core.entity.SendingAttachment</class>
    <class>com.haulmont.cuba.core.entity.EntitySnapshot</class>
    <class>com.haulmont.cuba.core.entity.ScheduledTask</class>
    <class>com.haulmont.cuba.core.entity.ScheduledExecution</class>
    <class>com.haulmont.cuba.core.entity.QueryResult</class>
    <class>com.haulmont.cuba.core.entity.AccessToken</class>
    <class>com.haulmont.cuba.core.entity.RefreshToken</class>
    <class>com.haulmont.cuba.security.entity.User</class>
    <class>com.haulmont.cuba.security.entity.Role</class>
    <class>com.haulmont.cuba.security.entity.UserRole</class>
    <class>com.haulmont.cuba.security.entity.Group</class>
    <class>com.haulmont.cuba.security.entity.GroupHierarchy</class>
    <class>com.haulmont.cuba.security.entity.Permission</class>
    <class>com.haulmont.cuba.security.entity.Constraint</class>
    <class>com.haulmont.cuba.security.entity.LocalizedConstraintMessage</class>
    <class>com.haulmont.cuba.security.entity.SessionAttribute</class>
    <class>com.haulmont.cuba.security.entity.UserSetting</class>
    <class>com.haulmont.cuba.security.entity.UserSubstitution</class>
    <class>com.haulmont.cuba.security.entity.LoggedEntity</class>
    <class>com.haulmont.cuba.security.entity.LoggedAttribute</class>
    <class>com.haulmont.cuba.security.entity.EntityLogItem</class>
    <class>com.haulmont.cuba.security.entity.FilterEntity</class>
    <class>com.haulmont.cuba.security.entity.SearchFolder</class>
    <class>com.haulmont.cuba.security.entity.Presentation</class>
    <class>com.haulmont.cuba.security.entity.ScreenHistoryEntity</class>
    <class>com.haulmont.cuba.security.entity.SessionLogEntry</class>
    <class>com.haulmont.cuba.core.entity.CategorizedEntity</class>
    <class>com.haulmont.cuba.core.entity.Category</class>
    <class>com.haulmont.cuba.core.entity.CategoryAttribute</class>
    <class>com.haulmont.cuba.core.entity.CategoryAttributeValue</class>
    <class>com.haulmont.cuba.core.entity.JmxInstance</class>
    <class>com.haulmont.cuba.security.entity.RememberMeToken</class>
    <class>com.haulmont.cuba.core.entity.ReferenceToEntity</class>
    <class>com.non.cares.entity.Person</class>
    <class>com.non.cares.entity.IncidentReport</class>
    <class>com.non.cares.entity.Allegation</class>
    <class>com.non.cares.entity.Victim</class>
    <class>com.non.cares.entity.Reporter</class>
    <class>com.non.cares.entity.Perpetrator</class>
    <exclude-unlisted-classes/>
    <properties>
      <property name="eclipselink.cache.coordination.propagate-asynchronously" value="false"/>
      <property name="eclipselink.session-event-listener" value="com.haulmont.cuba.core.sys.persistence.EclipseLinkSessionEventListener"/>
      <property name="eclipselink.logging.logger" value="com.haulmont.cuba.core.sys.logging.EclipseLinkLog"/>
      <property name="eclipselink.cache.shared.default" value="false"/>
      <property name="eclipselink.flush-clear.cache" value="Merge"/>
      <property name="eclipselink.target-database" value="com.haulmont.cuba.core.sys.persistence.CubaHSQLPlatform"/>
      <property name="javax.persistence.validation.mode" value="NONE"/>
      <property name="eclipselink.cache.coordination.protocol" value="com.haulmont.cuba.core.sys.entitycache.EntityCacheTransportManager"/>
      <property name="eclipselink.weaving" value="static"/>
    </properties>
  </persistence-unit> 
</persistence>

When I run the Unit Test, I get the following error:

Exception Description: [class com.non.cares.entity.Person] uses a non-entity [class com.non.rda.entity.ReferenceData] as target entity in the relationship attribute [field countyOfResidence].

Both classes (ReferenceData and Person) extend the StandardEntity class. I suspect the cause is that the persistence.xml in the test folder path is unable to find the right ReferenceData class.

How do I fix this?

Thank you!

Hi,

Make sure the YourAppTestContainer class located in the test sources of the core module defines the app component in the constructor:

public class CaresTestContainer extends TestContainer {

    public CaresTestContainer() {
        super();
        appComponents = new ArrayList<>(Arrays.asList(
                "com.haulmont.cuba",
                // add CUBA premium add-ons here
                // "com.haulmont.bpm",
                // "com.haulmont.charts",
                // "com.haulmont.fts",
                // "com.haulmont.reports",
                // and custom app components if any
                "com.non.rda"
        ));
    }