2013-08-30 10 views
0

다음 두 스크립트를 사용하여 HSQL을 실행하고 테스트하려고하지만 처리 할 수없는 오류가 발생할 때마다 테스트합니다.봄 : HSQL- 데이터베이스 스크립트를 실행하지 못했습니다

데이터베이스 스크립트를 실행하지 못했습니다. 중첩 된 예외는 org.springframework.jdbc.datasource.init.ScriptStatementFailedException입니다 : 리소스 클래스 경로 자원 [data.sql]의 라인 4에서 SQL 스크립트 문을 실행하지 못했습니다 : spittle (spitter_id, spittleText, postedTime) 값 (2, 봄 '.의 새로운 표현 언어를'시도 '2010-06-11')

업데이트 - 추가 예외가 throw되었습니다 :

무결성 제약 조건 위반 : 외래 키 없음 부모의; SYS_FK_10108 테이블 :

insert into spitter (username, password, fullname, email, update_by_email) values ('habuma', 'password', 'Craig Walls', '[email protected]', false); 
insert into spitter (username, password, fullname, email, update_by_email) values ('artnames', 'password', 'Art Names', '[email protected]', false); 

insert into spittle (spitter_id, spittleText, postedTime) values (1, 'Have you read Spring in Action 3? I hear it is awesome!', '2010-06-09'); 
insert into spittle (spitter_id, spittleText, postedTime) values (2, 'Trying out Spring''s new expression language.', '2010-06-11'); 
insert into spittle (spitter_id, spittleText, postedTime) values (1, 'Who''s going to SpringOne/2GX this year?', '2010-06-19'); 

appContext.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:jdbc="http://www.springframework.org/schema/jdbc" 
    xsi:schemaLocation="http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-3.0.xsd 
     http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd"> 

    <jdbc:embedded-database id="dataSource" type="H2"> 
     <jdbc:script location="classpath:schema.sql" /> 
     <jdbc:script location="classpath:data.sql" /> 
    </jdbc:embedded-database> 

</beans> 
,691

schema.sql

drop table if exists spittle; 
drop table if exists spitter; 

create table spitter (
    id identity, 
    username varchar(25) not null, 
    password varchar(25) not null, 
    fullname varchar(100) not null, 
    email varchar(50) not null, 
    update_by_email boolean not null 
); 

create table spittle (
    id integer identity primary key, 
    spitter_id integer not null, 
    spittleText varchar(2000) not null, 
    postedTime date not null, 
    foreign key (spitter_id) references spitter(id) 
); 

data.sql : 침

이 내 스크립트입니다 363,210

유닛 테스트는

package com.habuma.spitter.persistence; 

import org.springframework.jdbc.datasource.embedded.EmbeddedDatabase; 
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder; 

public class DataAccessUnitTestTemplate { 
    private static EmbeddedDatabase db; 

    @Before 
    public void setUp() { 
     // creates a HSQL in-memory db populated from default scripts classpath:schema.sql and classpath:test-data.sql 
     // obviously, this is the 'in-code' method, but the xml should work for Spring managed tests. 
     db = new EmbeddedDatabaseBuilder().addDefaultScripts().build();  
    } 

    @Test 
    public void testDataAccess() { 
     JdbcSpitterDao jdbc = new JdbcSpitterDao(db); 

     System.out.println(jdbc.getSpitterById(1L)); 

    } 

    @After 
    public void tearDown() { 
     db.shutdown(); 
    } 


} 
+0

@SotiriosDelimanolis 준비된 문이'SQL_SELECT_SPITTER = 같다 "여기서 ID = spitter에서 아이디, 이름, 전체 이름을 선택?"'. 하지만 응용 프로그램을 테스트하고'setUp()'메서드에서 실패합니다 (다른 주석도 있음). – ashur

+0

@SotiriosDelimanolis 당신은 더 구체적 일 수 있습니까? 내가 뭘 제거해야할지 모르겠다. 나는 thas가 던진 두 번째 예외로 질문을 업데이트했습니다. – ashur

+0

@SotiriosDelimanolis 도움이되지 않았습니다. Log4j : WARN logger (org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseFactory)에서 appender를 찾을 수 없다는 것을 눈치 챘다. log4j : WARN log4j 시스템을 올바르게 초기화하십시오. '내 문제의 근원이 될 수 있습니까? – ashur

답변

1

스크립트 당신은 시작 값을 지정할 수 있습니다 0으로 ID 열 값을 시작합니다.

create table spitter (
    id int generated by default as identity (start with 1) primary key, 
    username varchar(25) not null, 
    password varchar(25) not null, 
    fullname varchar(100) not null, 
    email varchar(50) not null, 
    update_by_email boolean not null 
); 

또는 명시 적으로 ID를 삽입 할 수 있습니다

insert into spitter (id, username, password, fullname, email, update_by_email) values (1, 'habuma', 'password', 'Craig Walls', '[email protected]', false); 
관련 문제