문서의 이전 판입니다!
org.hibernate:hibernate-testing:${version.org.hibernate}
에 의존성을 가지고서 ORMUnitTestCase
를 참조하여 수정해서 만들면 좋다.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-core
→ org.jboss.logging:jboss-logging-spi
가 jboss-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/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() } }