사용자 도구

사이트 도구


java:hibernate:test

문서의 이전 판입니다!


Hibernate Test

Hibernate Test Case Template

  • Hibernate Issue Reporting 등을 할 때 테스트 케이스를 만들어서 제공해야 한다.
    • 자기가 테스트하고자하는 버전의 Template을 다운로드하여 자신만의 프로젝트에 복사해 넣고 이미 만들어져 있는 테스트 케이스 파일을 수정해서 해본다.
    • org.hibernate:hibernate-testing:${version.org.hibernate} 에 의존성을 가지고서 ORMUnitTestCase를 참조하여 수정해서 만들면 좋다.

hibernate-testing 사용시 Jboss Logging 문제

hibernate-testing 사용시 아래와 같이 jboss logging에 문제가 생길 수 있다.

java.lang.NoSuchMethodError: org.jboss.logging.Logger.getMessageLogger(Ljava/lang/Class;Ljava/lang/String;)Ljava/lang/Object;

이 이유는 hibernate-testing이 의존하고 있는 jboss-common-coreorg.jboss.logging:jboss-logging-spijboss-logging과 동일한 패키지의 Logger 클래스를 구현하고 있어서 두 라이브러리간 충돌이 발생하기 때문이다. org.jboss.logging:jboss-logging-spi exclude 처리한다.

testCompile(group: 'org.hibernate', name: 'hibernate-testing', version: hibernateVersion) {
    exclude group: 'org.jboss.logging', module: 'jboss-logging-spi'
}

Hibernate 4.2 미만 Spock Spec 기본 뼈대

/**
 * Hibernate/JPA testing specification.
 */
abstract class AbstractUserTypeSpec extends Specification {
 
    Configuration configuration;
 
    SessionFactory sf;
 
    void setup() {
        configuration = new Configuration();
 
 
        // configuration.addAnnotatedClass(ClassName) 형태로 @Entity들 추가
 
        configuration.setProperty("hibernate.show_sql", "true");
        configuration.setProperty("hibernate.format_sql", "true");
        configuration.setProperty("hibernate.hbm2ddl.auto", "update");
        configuration.setProperty("hibernate.dialect", "org.hibernate.dialect.H2Dialect");
        configuration.setProperty("hibernate.connection.driver_class", "org.h2.Driver");
        configuration.setProperty("hibernate.connection.url", "jdbc:h2:mem:testdb;DB_CLOSE_DELAY=-1");
        configuration.setProperty("hibernate.connection.username", "sa");
        configuration.setProperty("hibernate.hbm2ddl.auto", "create-drop");
 
        // hibernate 4.2.x 미만 의 ServiceRegistryBuilder 설정.
        // 4.x 끼리도 버전마다 조금씩 달라질 수 있다.
        def srBuilder = new ServiceRegistryBuilder().applySettings(configuration.getProperties())
        def serviceRegistry = srBuilder.buildServiceRegistry()
 
        sf = configuration.buildSessionFactory(serviceRegistry);
    }
 
    void cleanup() {
        sf.close()
    }
}
java/hibernate/test.1474184231.txt.gz · 마지막으로 수정됨: 2016/09/18 16:07 저자 kwon37xi