My associates and I are experiencing inconsistent behavior when creating a simple test application using the airhacks java EE 8 project from Archetype.

We create a simple POJO and label it with the Entity annotation, such as

@Entity
public class GroceryItem {  ...   }

In Apache NetBeans 12, @Entity has a warning underline. When we select the warning (or do Alt+Enter), we see an option to "Create Persistence Unit", which we click.

However, I'm able to do this just fine.

enter image description here

I select the jdbc:derby:// option, hit Create, and then it creates the persistence.xml file in Other Sources ... META-INF as I expect. This is the original persistence.xml:

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.1" 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">
  <persistence-unit name="somePU" transaction-type="RESOURCE_LOCAL">
    <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
    <exclude-unlisted-classes>false</exclude-unlisted-classes>
    <properties>
      <property name="javax.persistence.jdbc.url" value="jdbc:derby://localhost:1527/sample"/>
      <property name="javax.persistence.jdbc.user" value="app"/>
      <property name="javax.persistence.jdbc.driver" value="org.apache.derby.jdbc.ClientDriver"/>
      <property name="javax.persistence.jdbc.password" value="app"/>
      <property name="javax.persistence.schema-generation.database.action" value="drop-and-create"/>
    </properties>
  </persistence-unit>
</persistence>

I modify this to use JTA and remove the reference to most of the properties, resulting in the following:

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.1" 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">
  <persistence-unit name="somePU" transaction-type="JTA">
    <exclude-unlisted-classes>false</exclude-unlisted-classes>
    <properties>
      <property name="javax.persistence.schema-generation.database.action" value="drop-and-create"/>
    </properties>
  </persistence-unit>
</persistence>

Note that I've changed the transaction-type attribute to "JTA" from "RESOURCE_LOCAL".

Now, I just go to the command line and create a grocery-list.war file using

mvn package

and then I run it with Payara:

java -jar payara.jar --deploy "path-to-the-war-file" --port 8080

I see the resultant Payara REST URLS that I've expected and they work great.

However, my associates get stuck at the "Create Persistence Unit" step. They don't see the jdbc:derby://localhost... option at all. They have the same Apache NetBeans that I do, and also have Payara micro, just like I'm using. They are unable to create the persistence.xml file through this process.

I've read that perhaps Derby is having support dropped on some platforms, but I can't understand why mine works just fine and theirs doesn't given them the option.

I'm a bit new to this side of Java/Apache NetBeans (I've spent lots of time in Java SE, Android, and even done Web Services using ASP .NET Core MVC for REST and WSDL/SOAP, but this is all becoming very perplexing.

So, my question is: has anyone experienced this behavior and corrected it, or is there an effective workaround? Creating a persistence.xml through "New XML file" in NetBeans doesn't seem to do the trick - the icon is even different from when the "Create Persistence Unit" is chosen. This seems very complex and I'm having trouble reproducing their issues myself.

Thanks!

1

There are 1 answers

0
mtz1406 On

you missed to add jta-data-source in your persistence.xml:

<jta-data-source>### YOUR FULL DATASOURCE NAME ###</jta-data-source>

add that line after:

<persistence-unit name="somePU" transaction-type="JTA">