为什么我在本地TomEE 1.6中获得HsqlException?

时间:2013-12-06 19:38:30

标签: mysql hibernate hsqldb tomee

org.hsqldb.HsqlException:用户缺少未找到的权限或对象:ENRG

enrg是一个表名。它在数据库中,我以root身份连接。所以这个错误信息至少可以说是误导。由于我的应用程序使用的是Hibernate jar,我甚至不明白为什么我会看到这个。基于我在Web上发现的内容,可能是我在Eclipse中启动的本地TomEE 1.6的一些配置错误。不过,我还没弄清楚如何去做。

只是为了证明它不是sql或权限问题: 此代码因上述异常而失败:

Query q=entityManager.createNativeQuery("insert into enrg values (null, 'ws', null, 'test', 'notes');");
q.executeUpdate();

我复制此插入并将其粘贴到MySQL命令行客户端,它工作正常。两种情况下的登录凭据都是相同的(root / root)。

异常位于此jar中:c:\ tomee16 \ lib \ sqldb-2.3.0.jar

我正在使用JPA 2.0和Hibernate 4。

的persistence.xml

<?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">

<persistence-unit name="default" transaction-type="JTA">
    <provider>org.hibernate.ejb.HibernatePersistence</provider>
    <class>my classess</class>
    <exclude-unlisted-classes>false</exclude-unlisted-classes>


    <properties>
        <property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver" />
        <property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/dbname?useUnicode=yes&amp;characterEncoding=utf8;" />
        <property name="javax.persistence.jdbc.user" value="root" />
        <property name="javax.persistence.jdbc.password" value="root" />

        <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect" />
        <property name="hibernate.show_sql" value="true" />
    </properties>

    </persistence-unit>

</persistence>

更新

Query q=entityManager.createNativeQuery("show tables;");会导致java.sql.SQLSyntaxErrorException: unexpected token: SHOW。我的应用程序不知道它正在与MySQL数据库交谈。

另外,在启动时,这里有几个警告: 警告:jar'C:\ javawork \ webadmin.metadata.plugins \ org.eclipse.wst.server.core \ tmp0 \ wtpwebapps \ WebAdmin \ WEB-INF \ lib \ hibernate-jpa-2.0-api-1.0.1.Final .jar'包含违规类:javax.persistence.Entity。它会被忽略。 警告:jar'C:\ javawork \ webadmin.metadata.plugins \ org.eclipse.wst.server.core \ tmp0 \ wtpwebapps \ WebAdmin \ WEB-INF \ lib \ jboss-transaction-api_1.1_spec-1.0.1.Final .jar'包含有问题的类:javax.transaction.Transaction。它会被忽略。 2013年12月7日上午1:22:37 org.apache.openejb.config.ConfigurationFactory configureApplication

1 个答案:

答案 0 :(得分:0)

原来从未连接到数据库的应用程序。通过服务器位置更改添加到tomee.xml的数据源可以建立连接。

更多信息:How to verify entity manager can establish a connection to the database?

相关问题