How to Improve OpenJPA with Ant + IntelliJ IDEA

It drives me crazy and I'm shocked by the official documentation

According to the official documentation, I added the following target

<target name="enhance"> <copy includeemptydirs="false" todir="${basedir}/lib/openjpa"> <fileset dir="src" excludes="**/*.launch, **/*.java"/> </copy> <taskdef name="openjpac" classname="org.apache.openjpa.ant.PCEnhancerTask"> <classpath refid="library.openjpa.classpath"/> </taskdef> <openjpac> <classpath refid="library.openjpa.classpath"/> </openjpac> </target> 

It gives me an exception

C: \ work \ prj \ build.xml: 283: org.apache.openjpa.util.MetaDataException: MetaDataFactory cannot be configured (conf.newMetaDataFactoryInstance () returns null). This may mean that no configuration properties were detected. Make sure you have META-INF / persistence.xml, that it is available in your classpath, or that the properties file that you use for configuration is available. If you are using Ant, see the attributes of the specified nested element. This can also happen if your OpenJPA distribution banks are damaged or if your security policy is too strict.

I tested and could see that it opens and reads persistence.xml .

Some person having the problems that I have and the answer he received was that the search for persistence.xml not the source of the problem.

Questions:

What can I do to make it work? Can I make it work by skipping the need for persistence.xml and just specifying a template for .class files. I want to improve? This is an Ant question. How can I force the OpenJPA enhancer to look for persistence.xml in a directory other than where openjpa-2.1.1.jar is located?
+6
source share
2 answers

Therefore, I could not get it to work without the undocumented propertiesFile . Here is the version that works for me. Also, specifying a persistence unit through # makes it fail with a NullReferenceException.

 <target name="enhance"> <taskdef name="openjpac" classname="org.apache.openjpa.ant.PCEnhancerTask"> <classpath refid="library.openjpa.classpath"/> </taskdef> <openjpac> <classpath refid="library.openjpa.classpath"/> <classpath location="${reporting.output.dir}"/> <config propertiesFile = "${basedir}/src/META-INF/persistence.xml"/> </openjpac> </target> 
+8
source

It looks like you might have missed an important part of the documentation. Your library.openjpa.classpath missing a reference to your objects and the location of the persistence.xml file. Try adding this and see how it happens.

 <path id="jpa.enhancement.classpath"> <pathelement location="bin"/> <!-- add something like this --> <!-- lib contains all of the jars that came with the OpenJPA binary download --> <fileset dir="lib"> <include name="**/*.jar"/> </fileset> </path> 
0
source

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


All Articles