DataNucleus, Maven, schema-create fails

时光怂恿深爱的人放手 提交于 2019-12-11 03:07:31

问题


I am trying to create a maven project with DataNucleus and MySQL. However, when i try to build and mvn datanucleus:schema-create the project, I get a failure. I can't figure out why.

Here is the persistence.xml class, and it is present in the classes/META-INF folder of the built project:

<?xml version="1.0" encoding="UTF-8" ?>
<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">

    <!-- JDO tutorial "unit" -->
    <persistence-unit name="Tutorial">
        <class>hello.Counter</class>
        <exclude-unlisted-classes>true</exclude-unlisted-classes>
        <properties>
            <property name="javax.jdo.option.ConnectionURL" value="jdbc:mysql://localhost/glu" />
            <property name="javax.jdo.option.ConnectionDriverName"
                value="com.mysql.jdbc.Driver" />
            <property name="javax.jdo.option.ConnectionUserName" value="root" />
            <property name="javax.jdo.option.ConnectionPassword" value="root" />

            <property name="datanucleus.schema.autoCreateAll" value="true" />
            <property name="datanucleus.schema.validateTables" value="true" />
            <property name="datanucleus.schema.validateConstraints"
                value="true" />
            <property name="javax.jdo.PersistenceManagerFactoryClass"
                value="org.datanucleus.api.jdo.JDOPersistenceManagerFactory" />
        </properties>
    </persistence-unit>
</persistence>

Here is the pom.xml i am trying to use.

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>ru.sf0.one</groupId>
    <artifactId>two</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>glu</name>


    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.2.1.RELEASE</version>
    </parent>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>com.jayway.jsonpath</groupId>
            <artifactId>json-path</artifactId>
            <!-- <version>1.2.0</version> -->
        </dependency>


        <dependency>
            <groupId>javax.jdo</groupId>
            <artifactId>jdo-api</artifactId>
            <version>3.0.1</version>
        </dependency>
        <dependency>
            <groupId>org.datanucleus</groupId>
            <artifactId>datanucleus-core</artifactId>
            <!-- scope>runtime</scope -->
            <version>4.0.4</version>
        </dependency>
        <dependency>
            <groupId>org.datanucleus</groupId>
            <artifactId>datanucleus-api-jdo</artifactId>
            <version>4.0.4</version>
        </dependency>


        <dependency>
            <groupId>org.datanucleus</groupId>
            <artifactId>datanucleus-rdbms</artifactId>
            <scope>runtime</scope>
            <version>4.0.4</version>
        </dependency>

        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <scope>runtime</scope>
        </dependency>

        <dependency>
            <groupId>org.datanucleus</groupId>
            <artifactId>datanucleus-accessplatform-jdo-rdbms</artifactId>
            <version>4.0.4</version>
            <type>pom</type>
        </dependency>


    </dependencies>


    <build>

        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <!-- <version>3.2</version> -->
                <configuration>
                    <source>1.7</source>
                    <target>1.7</target>
                </configuration>
            </plugin>

            <plugin>
                <groupId>org.datanucleus</groupId>
                <artifactId>datanucleus-maven-plugin</artifactId>
                <version>4.0.0-release</version>


                <configuration>
                    <api>JDO</api>
                    <persistenceUnitName>Tutorial</persistenceUnitName>
                    <log4jConfiguration>${basedir}/src/main/resources/log4j.properties</log4jConfiguration>
                    <verbose>false</verbose>
                </configuration>
                <executions>
                    <execution>
                        <phase>process-classes</phase>
                        <goals>
                            <goal>enhance</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>


        </plugins>
    </build>

    <repositories>
        <repository>
            <id>spring-releases</id>
            <url>https://repo.spring.io/libs-release</url>
        </repository>
    </repositories>
    <pluginRepositories>
        <pluginRepository>
            <id>spring-releases</id>
            <url>https://repo.spring.io/libs-release</url>
        </pluginRepository>
    </pluginRepositories>
</project>

The error that I get is:

~>2015-02-23 00:26:55 DEBUG MetaData:58 - Class "hello.Counter" field "count" : Adding Meta-Data for field since it didnt appear in the Meta-Data definition.
~>2015-02-23 00:26:55 DEBUG MetaData:58 - Initialising all MetaData ...
~>2015-02-23 00:26:55 DEBUG MetaData:58 - Class "hello.Counter" : Initialising Meta-Data
~>2015-02-23 00:26:55 DEBUG MetaData:58 - MetaData Management : Load of Metadata complete
~>2015-02-23 00:26:55 DEBUG Datastore:58 - Creating StoreManager for datastore
~>2015-02-23 00:26:55 ERROR Datastore:125 - Exception thrown creating StoreManager. See the nested exception
There is no available StoreManager of type "jdbc". Make sure that you have put the relevant DataNucleus store plugin in your CLASSPATH and if defining a connection via JNDI or DataSource you also need to provide persistence property "datanucleus.storeManagerType"
org.datanucleus.exceptions.NucleusUserException: There is no available StoreManager of type "jdbc". Make sure that you have put the relevant DataNucleus store plugin in your CLASSPATH and if defining a connection via JNDI or DataSource you also need to provide persistence property "datanucleus.storeManagerType"
    at org.datanucleus.NucleusContextHelper.createStoreManagerForProperties(NucleusContextHelper.java:223)
    at org.datanucleus.PersistenceNucleusContextImpl.initialise(PersistenceNucleusContextImpl.java:433)
    at org.datanucleus.store.schema.SchemaTool.getNucleusContextForMode(SchemaTool.java:693)
    at org.datanucleus.store.schema.SchemaTool.main(SchemaTool.java:286)
~>2015-02-23 00:26:55 ERROR SchemaTool:125 - Error creating NucleusContext
There is no available StoreManager of type "jdbc". Make sure that you have put the relevant DataNucleus store plugin in your CLASSPATH and if defining a connection via JNDI or DataSource you also need to provide persistence property "datanucleus.storeManagerType"
org.datanucleus.exceptions.NucleusUserException: There is no available StoreManager of type "jdbc". Make sure that you have put the relevant DataNucleus store plugin in your CLASSPATH and if defining a connection via JNDI or DataSource you also need to provide persistence property "datanucleus.storeManagerType"
    at org.datanucleus.NucleusContextHelper.createStoreManagerForProperties(NucleusContextHelper.java:223)
    at org.datanucleus.PersistenceNucleusContextImpl.initialise(PersistenceNucleusContextImpl.java:433)
    at org.datanucleus.store.schema.SchemaTool.getNucleusContextForMode(SchemaTool.java:693)
    at org.datanucleus.store.schema.SchemaTool.main(SchemaTool.java:286)
An error was encountered creating a PersistenceManagerFactory : There is no available StoreManager of type "jdbc". Make sure that you have put the relevant DataNucleus store plugin in your CLASSPATH and if defining a connection via JNDI or DataSource you also need to provide persistence property "datanucleus.storeManagerType" - please consult the log for more information.

UPD If i remove the <scope>runtime</scope> restriction from datanucleus-rdbms, I get the following error:

~>2015-02-23 12:07:34 DEBUG MetaData:58 - Class "hello.Counter" field "count" : Adding Meta-Data for field since it didnt appear in the Meta-Data definition.
~>2015-02-23 12:07:34 DEBUG MetaData:58 - Initialising all MetaData ...
~>2015-02-23 12:07:34 DEBUG MetaData:58 - Class "hello.Counter" : Initialising Meta-Data
~>2015-02-23 12:07:34 DEBUG MetaData:58 - MetaData Management : Load of Metadata complete
~>2015-02-23 12:07:34 DEBUG Datastore:58 - Creating StoreManager for datastore
~>2015-02-23 12:07:34 ERROR Datastore:125 - Exception thrown creating StoreManager. See the nested exception
Error creating transactional connection factory
org.datanucleus.exceptions.NucleusException: Error creating transactional connection factory
    at org.datanucleus.store.AbstractStoreManager.registerConnectionFactory(AbstractStoreManager.java:219)
    at org.datanucleus.store.AbstractStoreManager.<init>(AbstractStoreManager.java:163)
    at org.datanucleus.store.rdbms.RDBMSStoreManager.<init>(RDBMSStoreManager.java:288)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:408)
    at org.datanucleus.plugin.NonManagedPluginRegistry.createExecutableExtension(NonManagedPluginRegistry.java:606)
    at org.datanucleus.plugin.PluginManager.createExecutableExtension(PluginManager.java:301)
    at org.datanucleus.NucleusContextHelper.createStoreManagerForProperties(NucleusContextHelper.java:193)
    at org.datanucleus.PersistenceNucleusContextImpl.initialise(PersistenceNucleusContextImpl.java:433)
    at org.datanucleus.store.schema.SchemaTool.getNucleusContextForMode(SchemaTool.java:693)
    at org.datanucleus.store.schema.SchemaTool.main(SchemaTool.java:286)
Caused by: java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:408)
    at org.datanucleus.plugin.NonManagedPluginRegistry.createExecutableExtension(NonManagedPluginRegistry.java:606)
    at org.datanucleus.plugin.PluginManager.createExecutableExtension(PluginManager.java:330)
    at org.datanucleus.store.AbstractStoreManager.registerConnectionFactory(AbstractStoreManager.java:205)
    ... 12 more
Caused by: java.lang.NullPointerException
    at org.datanucleus.store.rdbms.ConnectionFactoryImpl.initialiseDataSources(ConnectionFactoryImpl.java:110)
    at org.datanucleus.store.rdbms.ConnectionFactoryImpl.<init>(ConnectionFactoryImpl.java:82)
    ... 19 more
Nested Throwables StackTrace:
java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:408)
    at org.datanucleus.plugin.NonManagedPluginRegistry.createExecutableExtension(NonManagedPluginRegistry.java:606)
    at org.datanucleus.plugin.PluginManager.createExecutableExtension(PluginManager.java:330)
    at org.datanucleus.store.AbstractStoreManager.registerConnectionFactory(AbstractStoreManager.java:205)
    at org.datanucleus.store.AbstractStoreManager.<init>(AbstractStoreManager.java:163)
    at org.datanucleus.store.rdbms.RDBMSStoreManager.<init>(RDBMSStoreManager.java:288)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:408)
    at org.datanucleus.plugin.NonManagedPluginRegistry.createExecutableExtension(NonManagedPluginRegistry.java:606)
    at org.datanucleus.plugin.PluginManager.createExecutableExtension(PluginManager.java:301)
    at org.datanucleus.NucleusContextHelper.createStoreManagerForProperties(NucleusContextHelper.java:193)
    at org.datanucleus.PersistenceNucleusContextImpl.initialise(PersistenceNucleusContextImpl.java:433)
    at org.datanucleus.store.schema.SchemaTool.getNucleusContextForMode(SchemaTool.java:693)
    at org.datanucleus.store.schema.SchemaTool.main(SchemaTool.java:286)
Caused by: java.lang.NullPointerException
    at org.datanucleus.store.rdbms.ConnectionFactoryImpl.initialiseDataSources(ConnectionFactoryImpl.java:110)
    at org.datanucleus.store.rdbms.ConnectionFactoryImpl.<init>(ConnectionFactoryImpl.java:82)
    ... 19 more

回答1:


The error message Make sure that you have put the relevant DataNucleus store plugin in your CLASSPATH says all you really need to know. The datanucleus-rdbms plugin is NOT in the CLASSPATH ... your scope restriction on runtime



来源:https://stackoverflow.com/questions/28658794/datanucleus-maven-schema-create-fails

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!