gpt4 book ai didi

jndi - persistence.xml 中的错误

转载 作者:行者123 更新时间:2023-12-04 23:05:41 24 4
gpt4 key购买 nike

我正在尝试将一个简单的 EJB 项目部署到 Jboss 7.1.1。我有单独安装的 H2 数据库。

所以我改变了standalone.xml如下:

        <subsystem xmlns="urn:jboss:domain:datasources:1.0">
<datasources>
<datasource jndi-name="java:jboss/datasources/ExampleDS" pool-name="ExampleDS" enabled="true" use-java-context="true">
<connection-url>jdbc:h2:tcp://localhost/~/test</connection-url>
<driver>h2</driver>
<security>
<user-name>sa</user-name>
<password>sa</password>
</security>
</datasource>
<drivers>
<driver name="h2" module="com.h2database.h2">
<xa-datasource-class>org.h2.jdbcx.JdbcDataSource</xa-datasource-class>
</driver>
</drivers>
</datasources>
</subsystem>

现在我还编辑了persistence.xml 以匹配standalone.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="scube" transaction-type="JTA">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<class>com.sample.model.Property</class>

<jta-data-source>java:jboss/datasources/ExampleDS</jta-data-source>

<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.H2Dialect" />
<property name="hibernate.max_fetch_depth" value="3" />
<property name="hibernate.hbm2ddl.auto" value="update" />
<property name="hibernate.show_sql" value="true" />
</properties>
</persistence-unit>
</persistence>

Eclipse,在行指出错误:java:jboss/datasources/ExampleDS
错误如下:
cvc-complex-type.2.4.a: Invalid content was found starting with element 'jta-data-source'. One of '{"http://java.sun.com/xml/ns/persistence":class, "http://java.sun.com/
xml/ns/persistence":exclude-unlisted-classes, "http://java.sun.com/xml/ns/persistence":shared-cache-mode, "http://java.sun.com/xml/ns/persistence":validation-mode,
"http://java.sun.com/xml/ns/persistence":properties}' is expected.

我搜索了类似的错误,所有的解决方案都说 xml 元素的顺序很重要,我检查过,或者 jndi 名称应该与 standalone.xml 匹配,它确实匹配。

有人可以帮我弄这个吗?

最佳答案

XML 元素的正确顺序(根据模式文档)是:

<provider>org.hibernate.ejb.HibernatePersistence</provider> 
<jta-data-source>java:jboss/datasources/ExampleDS</jta-data-source>
<class>com.sample.model.Property</class>

关于jndi - persistence.xml 中的错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13130162/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com