How to configure and batch Java application to use JPA

I am trying to learn JPA, and I want to create a simple Java command line application that will use JPA to query and update a database table. I outlined the simple code needed for this. But I do not know how to set up the directory structure, where to put the persistence.xml file, packaging, and so on. This is just a quick and dirty training exercise, so I want it to be as simple as possible. Can someone outline the steps to do this?

I am using Weblogic 10.3.

0
source share
2 answers

persistence.xml is in a directory META-INFthat is at the same level as your persistence classes. Here is an example of some valid and invalid configurations. In non-Java EE applications that I wrote, I create a JAR with persistence.xml in WEB-INF/classes/META-INF/, because my JPA classes are in WEB-INF/classes/.

+1
source

Not sure to understand that WebLogic is relevant to a Java command line application :)

In any case, all the data you are looking for is available in the Unity section ... in the Java EE 5 Tutorial , which I quote below:

Conservation Units

, EntityManager . , .

persistence.xml . JAR, META-INF persistence.xml . .

.

WAR EJB JAR JAR, WAR EAR .

JAR EJB, persistence.xml EJB JARs META-INF.

WAR, persistence.xml WAR WEB-INF/classes/META-INF.

JAR, WAR EAR, JAR :

  • WEB-INF/lib WAR.
  • EAR.
  • EAR.

persistence.xml

persistence.xml . persistence.xml.

<persistence>
    <persistence-unit name="OrderManagement">
        <description>This unit manages orders and customers.
            It does not rely on any vendor-specific features and can
            therefore be deployed to any persistence provider.
        </description>
        <jta-data-source>jdbc/MyOrderDB</jta-data-source>
        <jar-file>MyOrderApp.jar</jar-file>
        <class>com.widgets.Order</class>
        <class>com.widgets.Customer</class>
    </persistence-unit>
</persistence>

OrderManagement, , JTA jdbc/MyOrderDB. jar-file class : , . jar-file JAR , , .

jta-data-source ( JTA- ) non-jta-data-source (-JTA- ) JNDI- .

+1

Source: https://habr.com/ru/post/1725506/


All Articles