0

I'm trying to create a layered web proyect with an EAR. I divided the Entities from the DataAccess in order to only allow DataAccess to be called by BusinessLogic.

I'm actually getting this exception:

Object: co.edu.icesi.i2trading.entities.Statetype@21397ba0 is not a known entity type.

And I found here that I need to create a persistence.xml in the EAR, but I can't really understand how.

Sharing a persistence unit across components in a .ear file

I tried placing the XML file in the Configuration Files:

enter image description hereenter image description here

And referencing the jar with <jar-files> in the persistence.xml;

    <?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
    <persistence-unit name="I2TradingDataAccessPU" transaction-type="JTA">
        <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
        <jta-data-source>jdbc/I2DataSource</jta-data-source>
                <jar-file>../I2TradingEntities.jar</jar-file>
                <jar-file>../../I2TradingEntities.jar</jar-file>
        <shared-cache-mode>NONE</shared-cache-mode>
        <properties>
            <property name="eclipselink.target-server" value="None"/>
            <!-- <property name="eclipselink.logging.level" value="ALL"/> -->
            <property name="eclipselink.logging.level" value="WARNING"/> 
        </properties>
    </persistence-unit>
</persistence>

With no success. Any idea why? I'm very new to Web Developing and this is getting to my nerves.

I'm also getting this WARNING in the persistence.xml's DESIGN tab:

enter image description here

Community
  • 1
  • 1
AFP_555
  • 2,392
  • 4
  • 25
  • 45
  • Look at [this](http://stackoverflow.com/questions/40016269/entity-unknown-in-ear-with-persistence-unit-in-another-jar/40030861#40030861) question and its answer; it is basically the same question. – ujulu Oct 29 '16 at 06:58
  • Hello. I'm working with Netbeans and I just don't understand when they show the folder structure. My folder structure is completely different. Could you please tell me where to place the persistence.xml? – AFP_555 Oct 29 '16 at 07:24
  • I don't use Netbeans either and I cannot tell you how it is organizing projects; but I see a folder `dist` containing `I2Trading.ear`. If you expand the ear you can see the directory structure; if you can show me that I could try to tell you where you have to put the persistence.xml file. – ujulu Oct 29 '16 at 07:36

1 Answers1

0

I believe that the instruction jar-file interprets any path from the file that holds the persistence.xml... So, your configuration specifies that the Entities JAR are siblings of your EAR file.

The best (and easy) solution for your problem is to put the given persistence.xmlat the META-INF folder of your I2TradingEntities.jar and remove the <jar-file> instructions from it ... This will instruct the Application Server to create a PersistenceContext called "I2TradingDataAccessPU" and to detect any @Entity Class contained in that JAR.

Carlitos Way
  • 3,279
  • 20
  • 30