Karaf - Hibernate - MariaDB“无法完成架构更新”错误

时间:2016-02-22 13:44:21

标签: hibernate jpa mariadb apache-karaf karaf

我正在尝试使用 Karaf 4.0.4 + Hibernate 4.3.6.Final 设置项目,我正在使用 MariaDB 10.0.23 < / strong>作为数据库。

我已经关注并尝试了this tutorial但是:

  • 我想使用pax-jdbc-config来创建数据源(因为不推荐使用数据源蓝图),而不是使用数据源blueprint.xml。
  • 我必须使用MariaDB而不是MySQL。所以我假设我必须更改一些配置文件以使用MariaDB驱动程序

结果,这是我的配置:

  1. org.ops4j.datasource-sampleprj.cfg

    osgi.jdbc.driver.name=mariadb
    osgi.jdbc.driver.class=org.mariadb.jdbc.Driver
    url=jdbc:mysql://DB_SERVER:3306/sampleprjdb
    dataSourceName=sampleprj
    databaseName=sampleprjdb
    user=myuser
    password=mypassword
    
  2. 我确定我的数据库凭据和数据库名称是正确的。

    1. sample-prj bundle&gt; persistence.xml

      <?xml version="1.0" encoding="UTF-8"?> 
      <persistence version="2.0"
          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">
          <persistence-unit name="sampleprj" transaction-type="JTA">
              <provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
              <jta-data-source>
                  osgi:service/javax.sql.DataSource/(osgi.jndi.service.name=jdbc/sampleprj)      
              </jta-data-source>
              <properties>
                  <property name="hibernate.dialect"     value="org.hibernate.dialect.MySQL5Dialect" />
                  <property name="hibernate.hbm2ddl.auto" value="update" />
                  <property name="hibernate.show_sql" value="true" />
                  <property name="hibernate.format_sql" value="true" />
              </properties>
          </persistence-unit>
      </persistence>
      
    2. <jta-data-source>元素中,我尝试了上面的值和osgi:service/sampleprj但它们都不起作用。 我也尝试了不同的hibernate.dialect s作为由不正确的方言引起的大多数架构更新错误。

      1. sample-prj bundle&gt;的 blueprint.xml

        <?xml version="1.0" encoding="UTF-8"?>
        <blueprint default-activation="eager"
            xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
            xmlns:jpa="http://aries.apache.org/xmlns/jpa/v1.0.0" xmlns:tx="http://aries.apache.org/xmlns/transactions/v1.0.0"
        
            xsi:schemaLocation="
                    http://www.osgi.org/xmlns/blueprint/v1.0.0 http://www.osgi.org/xmlns/blueprint/v1.0.0 
                    http://www.w3.org/2001/XMLSchema-instance     http://www.w3.org/2001/XMLSchema-instance 
                    http://aries.apache.org/xmlns/jpa/v1.0.0 http://aries.apache.org/xmlns/jpa/v1.0.0 
                    http://aries.apache.org/xmlns/transactions/v1.0.0 http://aries.apache.org/xmlns/transactions/v1.0.0 ">
        
            <bean id="dbService"
                class="org.sample.project.persistence.mariadb.impl.DbServiceImpl">
                <jpa:context unitname="sampleprj" property="em"/>
                <tx:transaction method="*" value="Required" />
            </bean>
        
            <service ref="dbService" interface="org.sample.project.IDbService" />
        
        </blueprint>
        
      2. sample-prj bundle&gt;的的pom.xml

        <project>
        
        ...
        
        <build>
            <plugins>
                <plugin>
                    <groupId>org.apache.felix</groupId>
                    <artifactId>maven-bundle-plugin</artifactId>
                    <extensions>true</extensions>
                    <configuration>
                        <instructions>
                            <Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
                            <Meta-Persistence>META-INF/persistence.xml</Meta-Persistence>
                            <Bundle-Version>1.0.0</Bundle-Version>
                            <Bundle-ManifestVersion>2</Bundle-ManifestVersion>
                            <Manifest-Version>1</Manifest-Version>
                            <Import-Package>
                            org.apache.felix.service.command;version="[0.6,1)",
                            org.apache.felix.gogo.commands;version="[0.6,1)",
                            org.apache.karaf.shell.console;version="[2.2,4)",
                            org.hibernate.proxy,
                            javassist.util.proxy,
                            *
                            </Import-Package>
                        </instructions>
                    </configuration>
                </plugin>
            </plugins>
        </build>
        
        ...
        
        </project>
        
      3. 我还可以确认结果Manifest.MF包含Meta-Persistence属性。

        1. Karaf(干净)启动上,我使用这些命令安装相关捆绑包:

          feature:repo-add mvn:org.ops4j.pax.jdbc/pax-jdbc-features/0.5.0/xml/features
          feature:install transaction jndi pax-jdbc-mariadb pax-jdbc-config pax-jdbc-pool-dbcp2 jpa hibernate
          
        2. 当我使用bundle:list时,到目前为止,所有捆绑包似乎都已安装且有效

          1. 最后,我使用此命令安装我的样本包:

            bundle:install mvn:org.sample.prj/sample-prj/1.0
            
          2. 但它会打印这些日志消息:

            2016-02-22 15:38:44,035 | ERROR | pool-36-thread-1 | SchemaUpdate                     | 199 - org.jboss.logging.jboss-logging - 3.1.4.GA | HHH000299: Could not complete schema update
            java.lang.NullPointerException
                at org.hibernate.tool.hbm2ddl.SchemaUpdate.execute(SchemaUpdate.java:227)[188:org.hibernate.core:4.3.6.Final]
                at org.hibernate.tool.hbm2ddl.SchemaUpdate.execute(SchemaUpdate.java:178)[188:org.hibernate.core:4.3.6.Final]
                at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:522)[188:org.hibernate.core:4.3.6.Final]
                at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1857)[188:org.hibernate.core:4.3.6.Final]
                at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl$4.perform(EntityManagerFactoryBuilderImpl.java:850)[189:org.hibernate.entitymanager:4.3.6.Final]
                at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl$4.perform(EntityManagerFactoryBuilderImpl.java:843)[189:org.hibernate.entitymanager:4.3.6.Final]
                at org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl.withTccl(ClassLoaderServiceImpl.java:398)[188:org.hibernate.core:4.3.6.Final]
                at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:842)[189:org.hibernate.entitymanager:4.3.6.Final]
                at org.hibernate.osgi.OsgiPersistenceProvider.createContainerEntityManagerFactory(OsgiPersistenceProvider.java:112)[190:org.hibernate.osgi:4.3.6.Final]
                at org.apache.aries.jpa.container.impl.PersistenceProviderTracker.createAndCloseDummyEMF(PersistenceProviderTracker.java:105)[79:org.apache.aries.jpa.container:2.3.0]
                at org.apache.aries.jpa.container.impl.PersistenceProviderTracker.addingService(PersistenceProviderTracker.java:85)[79:org.apache.aries.jpa.container:2.3.0]
                at org.apache.aries.jpa.container.impl.PersistenceProviderTracker.addingService(PersistenceProviderTracker.java:44)[79:org.apache.aries.jpa.container:2.3.0]
                at org.osgi.util.tracker.ServiceTracker$Tracked.customizerAdding(ServiceTracker.java:941)[org.osgi.core-6.0.0.jar:]
                at org.osgi.util.tracker.ServiceTracker$Tracked.customizerAdding(ServiceTracker.java:870)[org.osgi.core-6.0.0.jar:]
                at org.osgi.util.tracker.AbstractTracked.trackAdding(AbstractTracked.java:256)[org.osgi.core-6.0.0.jar:]
                at org.osgi.util.tracker.AbstractTracked.trackInitial(AbstractTracked.java:183)[org.osgi.core-6.0.0.jar:]
                at org.osgi.util.tracker.ServiceTracker.open(ServiceTracker.java:318)[org.osgi.core-6.0.0.jar:]
                at org.osgi.util.tracker.ServiceTracker.open(ServiceTracker.java:261)[org.osgi.core-6.0.0.jar:]
                at org.apache.aries.jpa.container.impl.PersistenceBundleTracker.trackProvider(PersistenceBundleTracker.java:106)[79:org.apache.aries.jpa.container:2.3.0]
                at org.apache.aries.jpa.container.impl.PersistenceBundleTracker.findPersistenceUnits(PersistenceBundleTracker.java:90)[79:org.apache.aries.jpa.container:2.3.0]
                at org.apache.aries.jpa.container.impl.PersistenceBundleTracker.addingBundle(PersistenceBundleTracker.java:69)[79:org.apache.aries.jpa.container:2.3.0]
                at org.apache.aries.jpa.container.impl.PersistenceBundleTracker.addingBundle(PersistenceBundleTracker.java:40)[79:org.apache.aries.jpa.container:2.3.0]
                at org.osgi.util.tracker.BundleTracker$Tracked.customizerAdding(BundleTracker.java:469)[org.osgi.core-6.0.0.jar:]
                at org.osgi.util.tracker.BundleTracker$Tracked.customizerAdding(BundleTracker.java:415)[org.osgi.core-6.0.0.jar:]
                at org.osgi.util.tracker.AbstractTracked.trackAdding(AbstractTracked.java:256)[org.osgi.core-6.0.0.jar:]
                at org.osgi.util.tracker.AbstractTracked.trackInitial(AbstractTracked.java:183)[org.osgi.core-6.0.0.jar:]
                at org.osgi.util.tracker.BundleTracker.open(BundleTracker.java:156)[org.osgi.core-6.0.0.jar:]
                at org.apache.aries.jpa.container.impl.Activator.start(Activator.java:43)[79:org.apache.aries.jpa.container:2.3.0]
                at org.apache.felix.framework.util.SecureAction.startActivator(SecureAction.java:697)[org.apache.felix.framework-5.4.0.jar:]
                at org.apache.felix.framework.Felix.activateBundle(Felix.java:2226)[org.apache.felix.framework-5.4.0.jar:]
                at org.apache.felix.framework.Felix.startBundle(Felix.java:2144)[org.apache.felix.framework-5.4.0.jar:]
                at org.apache.felix.framework.BundleImpl.start(BundleImpl.java:998)[org.apache.felix.framework-5.4.0.jar:]
                at org.apache.felix.framework.BundleImpl.start(BundleImpl.java:984)[org.apache.felix.framework-5.4.0.jar:]
                at org.apache.karaf.features.internal.service.FeaturesServiceImpl.startBundle(FeaturesServiceImpl.java:1199)[9:org.apache.karaf.features.core:4.0.4]
                at org.apache.karaf.features.internal.service.Deployer.deploy(Deployer.java:840)[9:org.apache.karaf.features.core:4.0.4]
                at org.apache.karaf.features.internal.service.FeaturesServiceImpl.doProvision(FeaturesServiceImpl.java:1089)[9:org.apache.karaf.features.core:4.0.4]
                at org.apache.karaf.features.internal.service.FeaturesServiceImpl$1.call(FeaturesServiceImpl.java:985)[9:org.apache.karaf.features.core:4.0.4]
                at java.util.concurrent.FutureTask.run(FutureTask.java:262)[:1.7.0_45]
                at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)[:1.7.0_45]
                at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)[:1.7.0_45]
                at java.lang.Thread.run(Thread.java:744)[:1.7.0_45]
            

            我怀疑这里有一些丢失或错误的配置。我错过了什么?

            谢谢,Emre。

1 个答案:

答案 0 :(得分:0)

这可能是Aries JPA 2中的一个问题.Charlie Mordant今天刚给我发了一封邮件,上面写着他对Aries JPA 2进行的一些测试的结果。他提到了与hibernate类似的行为,他也希望通过持久性提供者。

本教程的主要区别可能是本教程使用的是不需要凭据登录的嵌入式。我将尝试在Aries JPA的测试中重现该问题。您能否在Apache Aries Jira

中为此打开一个问题