Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/386.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/239.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何模拟HSQL DB Junit的数据库会话_Java_Hibernate_Junit_Hsqldb - Fatal编程技术网

Java 如何模拟HSQL DB Junit的数据库会话

Java 如何模拟HSQL DB Junit的数据库会话,java,hibernate,junit,hsqldb,Java,Hibernate,Junit,Hsqldb,我有一个存储库实现类,如下所示 public class TesepositoryImpl extends OTPRepositoryBase implements TestRepository { public TesepositoryImpl() { super(RequiresOTPSession.YES); } @Override public int createPreference(AirDetail AirDeta

我有一个存储库实现类,如下所示

public class TesepositoryImpl extends OTPRepositoryBase implements
        TestRepository {

    public TesepositoryImpl() {
        super(RequiresOTPSession.YES);
    }

    @Override
    public int createPreference(AirDetail AirDetail)
            throws PersistenceException {
        Transaction tx = null;
        Session session = null;
        try {
            session = otpDatabaseSession.openSession();
            tx = session.beginTransaction();
            session.save(AirDetail);
            tx.commit();
        } finally {
            otpDatabaseSession.closeSession(session);
        }
                return AirDetail.getAirDetailId().intValue();
    }
我已经为上面提到的写junit

public class TesRepositoryImplTest {


    private EmbeddedDatabase db;

    @Before
    public void setUp() {
        db = new EmbeddedDatabaseBuilder().setType(EmbeddedDatabaseType.HSQL)
                .addScript("db/sql/create-db.sql")
                .addScript("db/sql/insert-data.sql").build();


    }   

    TesRepository testRepository = new TestRepositoryImpl();

    @Test
    public void createPreference() throws Exception {

        //*setting values** creating preference**/

        int airRefereID = testRepository
                .createPreference(preference);

    }



    @After
    public void tearDown() {
        db.shutdown();
    }
我将hibernate cfg文件定义如下

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
    <session-factory>
                <property name="connection.driver_class">org.hsqldb.jdbcDriver</property>
        <property name="connection.url">jdbc:hsqldb:mem:fcds</property>
        <property name="connection.username">SA</property>
        <property name="connection.password"></property>

        <property name="connection.pool_size">10</property>
        <property name="dialect">org.hibernate.dialect.HSQLDialect</property>
        <property name="connection.autocommit">true</property>

        <property name="hibernate.bytecode.use_reflection_optimizer">false</property>

        <property name="hibernate.current_session_context_class">thread</property>
        <property name="show_sql">true</property>
        <property name="format_sql">true</property>
        <property name="hibernate.bytecode.use_reflection_optimizer">false</property>
        <property name="hibernate.standard_service_registry_builder">false</property>
        <mapping class="com.aa.dotc.commons.domain.preference" />
    </session-factory>
</hibernate-configuration>

org.hsqldb.jdbcDriver
jdbc:hsqldb:mem:fcds
沙特阿拉伯
10
org.hibernate.dialogue.hsql方言
真的
假的
线
真的
真的
假的
假的
我需要知道下面的内容

当我调用testRepository时 .优先权(优先权)

我需要覆盖otpsession到HSQL会话

请帮助我如何实现上述使用HSQL或共享任何样本,以实现相同的