0

My question is pretty straightforward. Given the following POM:

<build>
    <plugins>
        <plugin>
            <groupId>org.datanucleus</groupId>
            <artifactId>maven-datanucleus-plugin</artifactId>
            <version>3.0.0-release</version>
            <configuration>
                <log4jConfiguration>${basedir}/src/main/resources/log4j.properties</log4jConfiguration>
                <verbose>true</verbose>
                <props>${basedir}/src/main/resources/datanucleus.properties</props>
            </configuration>
            <executions>
                <execution>
                    <phase>compile</phase>
                    <goals>
                        <goal>enhance</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>
<repositories>
    <repository>
        <id>DataNucleus_Repos2</id>
        <name>DataNucleus Repository</name>
        <url>http://www.datanucleus.org/downloads/maven2</url>
    </repository>
    <repository> <!-- Required for transaction-api transitive dep -->
        <id>Java_Net_LEGACY</id>
        <name>Java.Net legacy</name>
        <url>http://download.java.net/maven/1/</url>
        <layout>legacy</layout>
    </repository>
</repositories>
<pluginRepositories>
    <pluginRepository>
        <id>DataNucleus_2</id>
        <url>http://www.datanucleus.org/downloads/maven2/</url>
    </pluginRepository>
</pluginRepositories>

<dependencies>
    <dependency>
        <groupId>org.datanucleus</groupId>
        <artifactId>datanucleus-core</artifactId>
        <scope>runtime</scope>
        <version>3.0.2</version>
    </dependency>
    <dependency>
        <groupId>org.datanucleus</groupId>
        <artifactId>datanucleus-api-jdo</artifactId>
        <version>3.0.2</version>
    </dependency>        
    <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>1.2.16</version>
        </dependency>
    <dependency>
        <groupId>org.datanucleus</groupId>
        <artifactId>datanucleus-rdbms</artifactId>
        <version>3.0.2</version>
    </dependency>
    <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.9</version>
        </dependency>
    <dependency>
        <groupId>javax.jdo</groupId>
        <artifactId>jdo-api</artifactId>
        <version>3.0</version>
    </dependency>
    <dependency>
        <groupId>org.apache.geronimo.specs</groupId>
        <artifactId>geronimo-jpa_2.0_spec</artifactId>
        <version>1.0</version>
    </dependency>
    <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>5.1.18</version>
        </dependency>
</dependencies>

And given that I have the files log4j.properties and datanucleus.properties in their expected place, when I run

mvn compile

I get (taken from datanucleus.log file)

19:36:11,297 (main) ERROR [DataNucleus.Enhancer] - DataNucleus Enhancer completed with an error. Please review the enhancer log for full details. Some classes may have been enhanced but some caused errors Error creating the MetaDataManager for API "JDO" : org.datanucleus.exceptions.NucleusException: Error creating the MetaDataManager for API "JDO" : at org.datanucleus.NucleusContext.getMetaDataManager(NucleusContext.java:964) at org.datanucleus.enhancer.DataNucleusEnhancer.getMetaDataManager(DataNucleusEnhancer.java:261) at org.datanucleus.enhancer.DataNucleusEnhancer.getFileMetadataForInput(DataNucleusEnhancer.java:716) at org.datanucleus.enhancer.DataNucleusEnhancer.enhance(DataNucleusEnhancer.java:590) at org.datanucleus.enhancer.DataNucleusEnhancer.main(DataNucleusEnhancer.java:1390)

Caused by: java.lang.reflect.InvocationTargetException at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source) at java.lang.reflect.Constructor.newInstance(Unknown Source) at org.datanucleus.plugin.NonManagedPluginRegistry.createExecutableExtension(NonManagedPluginRegistry.java:681) at org.datanucleus.plugin.PluginManager.createExecutableExtension(PluginManager.java:314) at org.datanucleus.NucleusContext.getMetaDataManager(NucleusContext.java:958) ... 4 more

Caused by: java.lang.NoSuchFieldError: supportsORM at org.datanucleus.api.jdo.metadata.JDOMetaDataManager.(JDOMetaDataManager.java:142) ... 11 more

I would like to enable logging to see what queries are being done by my application. A thing to note is that the enhancement works fine when removing log4j dependency from the POM. Of course, the log file doesn't get updated anymore, but the classes are enhanced.

Any idea related to the above behaviour will be greatly appreciated.

Ariel Chelsău
  • 959
  • 3
  • 9
  • 20
  • What do you mean "queries"? You are enhancing your classes. And you are enhancing with one version of datanucleus-api-jdo (3.0.2), yet an inconsistent version of datanucleus-core (likely 3.0.10) pulled in by the enhancer. – DataNucleus May 01 '12 at 07:43
  • It's not clear to me why you're saying that I use datanucleus-api-jdo 3.0.2 and datanucleus-core 3.0.10, because in my POM above the version for the latter is 3.0.2. Maybe you refer to the plugin version (which is 3.0.0). I tried changing that but with no success. And by "queries" I mean that besides enhancing the classes it would be cool to see in the console the queries issued to the database (just as Hibernate does). – Ariel Chelsău May 01 '12 at 13:19
  • I refer to what the enhancer is using, that the DataNucleus M2 plugin is pulling in. Running maven with "--debug" would confirm this or otherwise. The fact remains you only get that exception is using mutually inconsistent versions of jars. Your error is in enhancement, so you haven't even started a PMF/EMF, and hence no queries ... one thing at a time – DataNucleus May 01 '12 at 13:25

1 Answers1

0

The documentation give a different look of the configuration for the plugin in particular in the executions:

<executions>
  <execution>
    <phase>process-classes</phase>
    <goals>
      <goal>enhance</goal>
    </goals>
  </execution>
</executions>

which might many problems. Furthermore you should remove the repository definitions from your pom, cause based on a short check all these dependencies are available via maven central. If you really need to configure the repositories you should use a repository manager instead.

khmarbaise
  • 92,914
  • 28
  • 189
  • 235
  • Thanks for the answer! You are right about the configuration for the plugin, I changed it first and now reverted the changes. I also commented out the repositories definition and it seems to throw the same error in the datanucleus.log file. I'll keep investigating this. – Ariel Chelsău Apr 30 '12 at 17:31