我有一个Java Webapp,
persistence.xml
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<persistence 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_2.xsd"
version="2.2">
<persistence-unit name="my-persistence-unit">
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
<exclude-unlisted-classes>false</exclude-unlisted-classes>
<properties>
<property name="javax.persistence.jdbc.driver" value="org.mariadb.jdbc.Driver"/>
<property name="javax.persistence.jdbc.url" value="jdbc:mariadb://localhost:3306/qltb"/>
<property name="javax.persistence.jdbc.user" value="root"/>
<property name="javax.persistence.jdbc.password" value="my_passwowrd"/>
<property name="hibernate.archive.autodetection" value="class"/>
<property name="hibernate.dialect" value="org.hibernate.dialect.MariaDB103Dialect"/>
<property name="hibernate.show_sql" value="true"/>
<property name="hibernate.format_sql" value="true"/>
<property name="hibernate.hbm2ddl.auto" value="update"/>
<property name="hbm2ddl.auto" value="update"/>
</properties>
</persistence-unit>
我创建一个简单的Bottle
@Entity
类,其中仅包含一个id和一个String属性。
运行此Web应用程序时,在日志中看到它正在处理my-persistence-unit
,但引发了异常:
org.hibernate.jpa.internal.util.LogHelper.logPersistenceUnitInformation HHH000204: Processing PersistenceUnitInfo [
name: my-persistence-unit
...]
... // Some lines are skipped
org.hibernate.tool.schema.spi.CommandAcceptanceException: Error executing DDL "
create table Bottle (
id bigint not null,
color varchar(255),
primary key (id)
) engine=InnoDB" via JDBC Statement
.... // Some lines are skipped
Caused by: org.hsqldb.HsqlException: unexpected token: ENGINE : line: 6
at org.hsqldb.error.Error.parseError(Unknown Source)
at org.hsqldb.ParserBase.unexpectedToken(Unknown Source)
at org.hsqldb.ParserCommand.compilePart(Unknown Source)
at org.hsqldb.ParserCommand.compileStatements(Unknown Source)
at org.hsqldb.Session.executeDirectStatement(Unknown Source)
at org.hsqldb.Session.execute(Unknown Source)
为什么JPA连接到hsqldb而不是persistence.xml中声明的MariaDB?
其他信息:我正在使用TomEE 8.0.0 M1
答案 0 :(得分:1)
我将resources.xml
添加到了WEB-INF
(而不是META-INF/context.xml
)中,内容如下:
<?xml version="1.0" encoding="UTF-8" ?>
<resources>
<Resource id="myDataSource" type="javax.sql.DataSource">
jdbcDriver=org.mariadb.jdbc.Driver
jdbcUrl = jdbc:mariadb://localhost:3306/qltb
userName = root
password = password
maxActive = 20
</Resource>
TomEE资源配置:http://tomee.apache.org/datasource-config.html
我仍然不知道persistence.xml
和resources.xml
之间的关系在哪里记录(在这种情况下)。我什至不需要<jta-data-source>
中的persistence.xml
标记