Issue
For to enhance the classes and to make normal Java classes "persistable", I have used DataNucleus Enhancer. The issue I am having is: No files to run datanucleus tool (error log shown below) and because of that datanucleus is not enhancing the classes. How the datanucleus run the files for enhancement?
Pom.xml
Dependencies of datanucleus
<dependency>
<groupId>org.datanucleus</groupId>
<artifactId>datanucleus-api-jdo</artifactId>
<version>4.0.5</version>
<!--<scope>compile</scope> -->
</dependency>
<dependency>
<groupId>org.datanucleus</groupId>
<artifactId>datanucleus-core</artifactId>
<version>4.0.6</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.datanucleus</groupId>
<artifactId>datanucleus-rdbms</artifactId>
<version>4.0.9</version>
<scope>runtime</scope>
</dependency>
Datanucleus Plugin for enhance
<plugin>
<groupId>org.datanucleus</groupId>
<artifactId>datanucleus-maven-plugin</artifactId>
<version>5.2.1</version>
<configuration>
<api>JDO</api>
<persistenceUnitName>MyUnit_Example</persistenceUnitName> <!-- todo: change persistance name-->
<log4jConfiguration>${pom.basedir}/data/log4j.properties</log4jConfiguration>
<generateConstructor>true</generateConstructor>
<verbose>true</verbose>
<alwaysDetachable>true</alwaysDetachable>
<metadataIncludes>${pom.basedir}/dir_name_1/dir_name_2/model**/*.class</metadataIncludes>
</configuration>
<executions>
<execution>
<phase>process-classes</phase>
<goals>
<goal>enhance</goal>
</goals>
</execution>
</executions>
</plugin>
Warning list
[INFO] --------------------------------[ jar ]---------------------------------
[WARNING] The POM for org.mortbay.jetty:servlet-api:jar:2.5-6.0.0beta12 is missing, no dependency information available
[INFO]
[INFO] --- datanucleus-maven-plugin:5.2.1:enhance (default-cli) @ forsteinrichtung ---
[WARNING] No files to run DataNucleus tool 'org.datanucleus.enhancer.DataNucleusEnhancer'
Solution
My setup for enhance the classes, I hope it could help you to find a solution. You need to add a persistence.xml, update the Datanucleus dependency artifact versions and add a dependency of javax.jdo for datanuclues which provides an interface to java model abstraction for persistence.
pom.xml
Depandancy for Datanucleus
<dependency>
<groupId>org.datanucleus</groupId>
<artifactId>datanucleus-api-jdo</artifactId>
<version>5.2.7</version>
<scope>compile</scope>
</dependencies>
<dependency>
<groupId>org.datanucleus</groupId>
<artifactId>datanucleus-core</artifactId>
<version>5.2.9</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.datanucleus</groupId>
<artifactId>datanucleus-rdbms</artifactId>
<version>5.2.9</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.datanucleus</groupId>
<artifactId>javax.jdo</artifactId>
<version>3.2.0-m11</version>
</dependency>
Datanucleus Plugin for enhance
<plugin>
<groupId>org.datanucleus</groupId>
<artifactId>datanucleus-maven-plugin</artifactId>
<version>5.2.1</version>
<configuration>
<api>JDO</api>
<persistenceUnitName>h2</persistenceUnitName>
<log4jConfiguration>${project.basedir}/data/config/log4j.properties</log4jConfiguration>
<verbose>true</verbose>
<fork>false</fork>
</configuration>
<dependencies>
<dependency>
<groupId>org.datanucleus</groupId>
<artifactId>datanucleus-core</artifactId>
<version>5.2.9</version>
<scope>runtime</scope>
</dependency>
</dependencies>
<executions>
<execution>
<phase>process-classes</phase>
<goals>
<goal>enhance</goal>
</goals>
</execution>
</executions>
</plugin>
persistence.xml
The location for persistence.xml
is "resources > META-INF > persistence.xml". If persistence.xml
does not exist then one need to create new persistence.xml
.
<persistence 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"
version="2.0">
<persistence-unit name="h2" transaction-type="RESOURCE_LOCAL">
<properties>
<property name="javax.persistence.jdbc.url" value="jdbc:h2:mem:test" />
<property name="javax.persistence.jdbc.driver" value="org.h2.Driver" />
<property name="hibernate.dialect" value="org.hibernate.dialect.H2Dialect" />
<property name="hibernate.format_sql" value="true" />
<property name="hibernate.show_sql" value="true" />
<property name="javax.persistence.schema-generation.database.action" value="create"/>
<property name="javax.persistence.schema-generation.create-source" value="script"/>
<property name="javax.persistence.schema-generation.create-script-source" value="sql/create.sql"/>
<!--<property name="javax.persistence.schema-generation.drop-source" value="script"/> -->
<!--<property name="javax.persistence.schema-generation.drop-script-source" value="sql/drop.sql"/> -->
<property name="javax.persistence.sql-load-script-source" value="sql/initial_data.sql" />
<property name="javax.persistence.jdbc.user" value="sa"/>
<property name="javax.persistence.jdbc.password" value="sa"/>
</properties>
</persistence-unit>
Answered By - umesh_sarkar
Answer Checked By - Dawn Plyler (JavaFixing Volunteer)