문서의 선택한 두 판 사이의 차이를 보여줍니다.
양쪽 이전 판 이전 판 다음 판 | 이전 판 마지막 판 양쪽 다음 판 | ||
java:hibernate:test [2016/09/18 14:10] kwon37xi |
java:hibernate:test [2016/09/18 17:11] kwon37xi [Hibernate 4.2 미만 Spock Spec 기본 뼈대] |
||
---|---|---|---|
줄 11: | 줄 11: | ||
* '' | * '' | ||
* [[https:// | * [[https:// | ||
+ | |||
+ | ===== hibernate-testing 사용시 Jboss Logging 문제 ===== | ||
+ | hibernate-testing 사용시 아래와 같이 jboss logging에 문제가 생길 수 있다. | ||
+ | < | ||
+ | java.lang.NoSuchMethodError: | ||
+ | </ | ||
+ | |||
+ | 이 이유는 hibernate-testing이 의존하고 있는 '' | ||
+ | '' | ||
+ | |||
+ | <code groovy> | ||
+ | testCompile(group: | ||
+ | exclude group: ' | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | ===== Hibernate 4.2 미만 Spock Spec 기본 뼈대 ===== | ||
+ | <code groovy> | ||
+ | /** | ||
+ | * Hibernate/ | ||
+ | */ | ||
+ | abstract class AbstractHibernateSessionSpec extends Specification { | ||
+ | |||
+ | Configuration configuration | ||
+ | |||
+ | SessionFactory sf | ||
+ | |||
+ | Session session | ||
+ | |||
+ | void setup() { | ||
+ | configuration = new Configuration(); | ||
+ | |||
+ | configuration.addAnnotatedClass(Article) | ||
+ | |||
+ | configuration.setProperty(" | ||
+ | configuration.setProperty(" | ||
+ | configuration.setProperty(" | ||
+ | configuration.setProperty(" | ||
+ | configuration.setProperty(" | ||
+ | configuration.setProperty(" | ||
+ | configuration.setProperty(" | ||
+ | |||
+ | // hibernate 4.2.x 미만 의 ServiceRegistryBuilder 설정. | ||
+ | // 4.x 끼리도 버전마다 조금씩 달라질 수 있다. | ||
+ | def srBuilder = new ServiceRegistryBuilder().applySettings(configuration.getProperties()) | ||
+ | def serviceRegistry = srBuilder.buildServiceRegistry() | ||
+ | |||
+ | sf = configuration.buildSessionFactory(serviceRegistry); | ||
+ | |||
+ | session = sf.openSession() | ||
+ | } | ||
+ | |||
+ | void cleanup() { | ||
+ | session.close() | ||
+ | sf.close() | ||
+ | } | ||
+ | } | ||
+ | |||
+ | // 테스트시 직접 Connection을 맺어 쿼리를 실행하고 검사하고 싶을 경우 | ||
+ | session.doWork({ Connection con -> | ||
+ | groovy.sql.Sql sql = new groovy.sql.Sql(con) | ||
+ | // work with Sql object | ||
+ | } as Work) | ||
+ | </ | ||
+ |