Junit org.hibernate.util.jdbceptionReporter-用户缺少权限或找不到对象

Junit org.hibernate.util.jdbceptionReporter-用户缺少权限或找不到对象,junit,hsqldb,Junit,Hsqldb,堆栈跟踪:WARN org.hibernate.util.jdbceptionReporter-SQL错误:-5501,SQLState:42501 错误org.hibernate.util.jdbceptionReporter-用户缺少权限或找不到对象:测试用例 我的applicationContext-junit-test.xml文件: <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://w

堆栈跟踪:WARN org.hibernate.util.jdbceptionReporter-SQL错误:-5501,SQLState:42501 错误org.hibernate.util.jdbceptionReporter-用户缺少权限或找不到对象:测试用例

我的applicationContext-junit-test.xml文件:

    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
        xsi:schemaLocation="http://www.springframework.org/schema/beans
    http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
    http://www.springframework.org/schema/context
    http://www.springframework.org/schema/context/spring-context-3.0.xsd">

            <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
            destroy-method="close">
            <property name="defaultAutoCommit" value="false">
            </property>
            <property name="driverClassName">
                <value>org.hsqldb.jdbcDriver</value>
            </property>
            <property name="url">
                <value>jdbc:hsqldb:mem:testcasedb;shutdown=true;hsqldb.write_delay=false;</value>
            </property>
            <property name="username">
                <value>sa</value>
            </property>
            <property name="password">
                <value></value>
            </property>

        </bean>
        <bean id="sessionFactory"
            class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
            <property name="dataSource">
                <ref bean="dataSource" />
            </property>
            <property name="hibernateProperties">
                <props>
                    <prop key="hibernate.dialect">org.hibernate.dialect.HSQLDialect</prop>
                    <prop key="hibernate.show_sql">true</prop>

                    <!-- <prop key="hibernate.hbm2ddl.auto">validate</prop> -->
                    <prop key="hibernate.connection.autocommit">true</prop>
                </props>
            </property>
            <property name="annotatedClasses">
                <list>
                    <value>com.rakuten.hashi.testcaseapi.dto.request.TestCase</value>
                </list>
            </property>
        </bean>
    </beans>

TestCase.java file:


    @Entity
    @Table(name = "test_case", schema = "testcase")
    @JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL)
    @XmlRootElement
    public class TestCase implements Serializable {

        @Id
        @GeneratedValue(strategy = GenerationType.AUTO)
        @Column(name = "ID", nullable = false)
        private Long Id;

        public Long getId() {
            return Id;
        }
        public void setId(Long id) {
            Id = id;
        }
    }

**DBUtil.java** runs the DDL and DML hsql files and DB is created successfully(I have printed DB on console).

      public class DBUtil {
                public static void createTestSchema() {
                    String sqlPath = "src/test/resources/sql";
                        ApplicationContext dbCtx = new ClassPathXmlApplicationContext("applicationContext-junit-test.xml");
                BasicDataSource ds = dbCtx.getBean(BasicDataSource.class);
                Connection conn = ds.getConnection();
                        Statement st = null;
                    try {
                        System.out.println("Creating Schema !");
                        File dir = new File(sqlPath);
                        File[] files = dir.listFiles();
                        SqlFile sqlFile;
                        for (File file : files) {
                                sqlFile = new SqlFile(file);
                                sqlFile.setConnection(conn);
                                sqlFile.execute();
                            }
                        }
    }

org.hsqldb.jdbcDriver
jdbc:hsqldb:mem:testcasedb;关机=真;hsqldb.write_delay=false;
sa
org.hibernate.dialogue.hsql方言
真的
真的
com.rakuten.hashi.testcaseapi.dto.request.TestCase
TestCase.java文件:
@实体
@表(name=“test\u case”,schema=“testcase”)
@JsonSerialize(include=JsonSerialize.Inclusion.NON_NULL)
@XmlRootElement
公共类TestCase实现了可序列化{
@身份证
@GeneratedValue(策略=GenerationType.AUTO)
@列(name=“ID”,nullable=false)
私人长Id;
公共长getId(){
返回Id;
}
公共无效集合id(长id){
Id=Id;
}
}
**java**运行DDL和DML hsql文件,成功创建了DB(我已经在控制台上打印了DB)。
公共类DBUtil{
公共静态void createTestSchema(){
字符串sqlPath=“src/test/resources/sql”;
ApplicationContext dbCtx=新类路径XmlApplicationContext(“ApplicationContext junit test.xml”);
BasicDataSource ds=dbCtx.getBean(BasicDataSource.class);
连接conn=ds.getConnection();
语句st=null;
试一试{
System.out.println(“创建模式!”);
File dir=新文件(sqlPath);
File[]files=dir.listFiles();
SqlFile-SqlFile;
用于(文件:文件){
sqlFile=新的sqlFile(文件);
setConnection(conn);
execute();
}
}
}
DaoImpl.java
我的HQL查询获取零结果(如果我将hbm2ddl.auto设置为“create”) 我的HQL查询抛出JDBCExceptionReporter:用户缺少权限或找不到对象(如果我不使用hbm2ddl.auto属性)

public类DaoImpl实现Dao{
@自动连线
私人会话工厂会话工厂;
public void getAllData(){
字符串hql=“fromtestcase”;
Session Session=sessionFactory.openSession();
列出结果;
试一试{
Query=session.createQuery(hql);
结果=query.list();//列表为空:[]
}捕获(例外e){
}
}
}

内存数据库的数据库URL属性错误。正确使用file:和mem:数据库的属性如下:

    <property name="url">
        <value>jdbc:hsqldb:file:testcasedb;shutdown=true;hsqldb.write_delay=false;</value>

    <property name="url">
        <value>jdbc:hsqldb:mem:testcasedb</value>

jdbc:hsqldb:file:testcasedb;shutdown=true;hsqldb.write\u delay=false;
jdbc:hsqldb:mem:testcasedb

如果对mem:数据库使用shutdown=true,则在上次打开的连接关闭时,所有数据都将被删除。对于文件数据库,所有数据都将被保存。

内存数据库的数据库URL属性错误。正确使用file:和mem:数据库的属性如下所示:

    <property name="url">
        <value>jdbc:hsqldb:file:testcasedb;shutdown=true;hsqldb.write_delay=false;</value>

    <property name="url">
        <value>jdbc:hsqldb:mem:testcasedb</value>

jdbc:hsqldb:file:testcasedb;shutdown=true;hsqldb.write\u delay=false;
jdbc:hsqldb:mem:testcasedb
如果对mem:database使用shutdown=true,则在上次打开的连接关闭时,所有数据都将被删除。对于文件数据库,所有数据都将被保存。

来自TestCase.java

我删除了@Table中的schema,它起作用了。我还删除了DDL和类似引用中的createschema

因此,更新后的TestCase.java将如下所示:

@Entity
@Table(name = "test_case")
@JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL)
@XmlRootElement
public class TestCase implements Serializable {

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Column(name = "ID", nullable = false)
    private Long Id;

    public Long getId() {
        return Id;
    }
    public void setId(Long id) {
        Id = id;
    }
}
来自TestCase.java

我删除了@Table中的schema,它起作用了。我还删除了DDL和类似引用中的createschema

因此,更新后的TestCase.java将如下所示:

@Entity
@Table(name = "test_case")
@JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL)
@XmlRootElement
public class TestCase implements Serializable {

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Column(name = "ID", nullable = false)
    private Long Id;

    public Long getId() {
        return Id;
    }
    public void setId(Long id) {
        Id = id;
    }
}

您好Fredt,我删除了关机和写入延迟,但仍然收到错误org.hibernate.util.jdbceptionReporter-用户缺少权限或未找到对象:TEST\u CASE您好Fredt,我删除了关机和写入延迟,但仍然收到错误org.hibernate.util.jdbceptionReporter-用户缺少权限或未找到对象:TEST\u CASE