无法解析名称org.hibernate.dialect.SQLiteDialect

时间:2016-03-09 06:58:08

标签: hibernate wildfly dialect

上周我说“让我们试试WildFly 10吧!”在基本配置和HelloWorld之后,我想看看持久性是如何工作的。 A拿了我的旧ABC EAR有一个JPA模块,其中Hibernate与SQLite一起使用。我设置了由net.kemitix提供的方言。

所以,我在POM文件中设置了它的依赖:

<dependency>
    <groupId>net.kemitix</groupId>
    <artifactId>sqlite-dialect</artifactId>
    <version>0.1.0</version>
</dependency>

包装后,EAR看起来像这样:

ABC_Ear-0.0.1-SNAPSHOT.ear
    lib
        ABC_Jpa-0.0.1-SNAPSHOT.jar
        sqlite-dialect-0.1.0.jar
        sqlite-jdbc-3.8.11.2.jar

persistence.xml:

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.1" xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
    <persistence-unit name="ABC_Jpa" transaction-type="JTA">
        <class>abc.jpa.User</class>
        <class>abc.jpa.Group</class>
        <properties>
            <property name="javax.persistence.jdbc.url" value="jdbc:sqlite:C:/sqlite/ABC.db"/>
            <property name="javax.persistence.jdbc.driver" value="org.sqlite.JDBC"/>
            <property name="jboss.entity.manager.factory.jndi.name" value="java:jboss/AbcEntityManagerFactory" />
            <property name="jboss.entity.manager.jndi.name" value="java:/AbcEntityManager"/>
            <property name="hibernate.dialect" value="org.hibernate.dialect.SQLiteDialect"/>
            <property name="hibernate.show_sql" value="true"/>
            <property name="hibernate.hbm2ddl.auto" value="create"/> 
        </properties>
    </persistence-unit>
</persistence>

在部署期间,会发生以下异常:

INFO  [org.jboss.as.jpa] (ServerService Thread Pool -- 67) WFLYJPA0010: Starting Persistence Unit (phase 2 of 2) Service 'ABC_Jpa-0.0.1-SNAPSHOT.jar#ABC_Jpa'
WARN  [org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator] (ServerService Thread Pool -- 67) HHH000342: Could not obtain connection to query metadata : Unable to resolve name [org.hibernate.dialect.SQLiteDialect] as strategy [org.hibernate.dialect.Dialect]
ERROR [org.jboss.msc.service.fail] (ServerService Thread Pool -- 67) MSC000001: Failed to start service jboss.persistenceunit."ABC_Jpa-0.0.1-SNAPSHOT.jar#ABC_Jpa": org.jboss.msc.service.StartException in service jboss.persistenceunit."ABC_Jpa-0.0.1-SNAPSHOT.jar#ABC_Jpa": org.hibernate.service.spi.ServiceException: Unable to create requested service [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment]
    at org.jboss.as.jpa.service.PersistenceUnitServiceImpl$1$1.run(PersistenceUnitServiceImpl.java:172)
    at org.jboss.as.jpa.service.PersistenceUnitServiceImpl$1$1.run(PersistenceUnitServiceImpl.java:117)
    at org.wildfly.security.manager.WildFlySecurityManager.doChecked(WildFlySecurityManager.java:667)
    at org.jboss.as.jpa.service.PersistenceUnitServiceImpl$1.run(PersistenceUnitServiceImpl.java:182)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)
    at org.jboss.threads.JBossThread.run(JBossThread.java:320)
Caused by: org.hibernate.service.spi.ServiceException: Unable to create requested service [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment]
    at org.hibernate.service.internal.AbstractServiceRegistryImpl.createService(AbstractServiceRegistryImpl.java:244)
    at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:208)
    at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:189)
    at org.hibernate.engine.jdbc.internal.JdbcServicesImpl.configure(JdbcServicesImpl.java:51)
    at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:94)
    at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:217)
    at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:189)
    at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.handleTypes(MetadataBuildingProcess.java:352)
    at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.complete(MetadataBuildingProcess.java:111)
    at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.metadata(EntityManagerFactoryBuilderImpl.java:847)
    at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:874)
    at org.jboss.as.jpa.hibernate5.TwoPhaseBootstrapImpl.build(TwoPhaseBootstrapImpl.java:44)
    at org.jboss.as.jpa.service.PersistenceUnitServiceImpl$1$1.run(PersistenceUnitServiceImpl.java:154)
    ... 7 more
Caused by: org.hibernate.boot.registry.selector.spi.StrategySelectionException: Unable to resolve name [org.hibernate.dialect.SQLiteDialect] as strategy [org.hibernate.dialect.Dialect]

我还试图加载包含方言的JAR和驱动程序本身,但结果相同:

C:\ wildfly-10.0.0.Final \模块\ SYSTEM \层\基\有机\ xerial \源码-JDBC \主\ module.xml

<module xmlns="urn:jboss:module:1.3" name="org.xerial.sqlite-jdbc">
    <resources>
        <resource-root path="sqlite-dialect-0.1.0.jar"/>
        <resource-root path="sqlite-jdbc-3.8.11.2.jar"/>
    </resources>
    <dependencies>
        <module name="javax.api"/>
        <module name="javax.transaction.api"/>
    </dependencies>
</module>

有人为这个问题找到了解决方法吗?同时我将再次阅读WildFly文档中的相关部分: - )

祝你好运, KérdezösködőIndián

3 个答案:

答案 0 :(得分:0)

对于PostgresSQL(为我工作)

我们需要在Wildfly 10中添加postgres JDBC驱动程序,因为我们在Wildfly中定义了数据源。

创建以下目录wildfly-10.0.0.Final/modules/org/postgresql/main/ 将module.xml复制到wildfly-10.0.0.Final/modules/org/postgresql/main /

将postgresql-9.4-1201-jdbc41.jar(可以下载)复制到wildfly-10.0.0.Final/modules/org/postgresql/main /

---- module.xml

<resources>
    <resource-root path="postgresql-9.4-1201-jdbc41.jar"/>
</resources>

<dependencies>
    <module name="javax.api"/>
    <module name="javax.transaction.api"/>
</dependencies>

答案 1 :(得分:0)

Hibernate对SQLite的支持已经停止,你可以通过包含外部依赖来解决这个问题。

在gradle.build文件中添加以下行。

repositories {
mavenCentral()
maven { url 'https://mvnrepository.com/artifact/net.kemitix/sqlite-dialect'}
}

并且

compile group: 'net.kemitix', name: 'sqlite-dialect', version: '0.1.0'

然后,将您的属性设置为 spring.jpa.database平台:org.hibernate.dialect.SQLiteDialect

答案 2 :(得分:0)

出错

<块引用>

无法解析名称 [org.hibernate.dialect.SQLiteDialect]

我通过更改 int application.properties 来解决这个问题:

# for sqlite3
spring.datasource.url=jdbc:sqlite:test_db
spring.datasource.driver-class-name=org.sqlite.JDBC
# old wrond value
#spring.jpa.database-platform=org.hibernate.dialect.SQLiteDialect
# nedd value
spring.jpa.database-platform=org.sqlite.hibernate.dialect.SQLiteDialect

以及 pom.xml 中的这个块:

    <dependency>
        <groupId>com.github.gwenn</groupId>
        <artifactId>sqlite-dialect</artifactId>
        <version>0.1.1</version>
    </dependency>
    <dependency>
        <groupId>org.xerial</groupId>
        <artifactId>sqlite-jdbc</artifactId>
        <version>3.30.1</version>
    </dependency>