Spring + Hibernate 4 + Glassfish 사용 JTA Transaction
모두 최신 버 전 일 것 입 니 다. Spring 프로필 은 다음 과 같 습 니 다.
02
<tx:annotation-driven /><!-- Spring @Transaction -->
03 <tx:jta-transaction-manager /><!-- Spring JTA -->
04
05 <bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
06 ...
07 <property name="hibernateProperties">
08 <value>
09
10 hibernate.current_session_context_class=jta<!-- 1 -->
11 hibernate.transaction.manager_lookup_class
=org.hibernate.transaction.SunONETransactionManagerLookup
12 </value>
13 </property>
14 </bean>
15 ...
키 설정 은 1 과 2 에 있 습 니 다: Hibernate 공식 문서 와 여기 설명 에 따 르 면:
When configuring Hibernate’s transaction factory, chooseorg.hibernate.transaction.JTATransactionFactory if you use JTA directly (BMT), and org.hibernate.transaction.CMTTransactionFactory in a CMT session bean. Remember to also set hibernate.transaction.manager_lookup_class. Ensure that your hibernate.current_session_context_class is either unset (backwards compatibility), or is set to "jta".
⋯⋯
See the Javadocs for the org.hibernate.context.spi.CurrentSessionContext interface for a detailed discussion of its contract. It defines a single method, currentSession(), by which the implementation is responsible for tracking the current contextual session. Out-of-the-box, Hibernate comes with three implementations of this interface: org.hibernate.context.internal.JTASessionContext: current sessions are tracked and scoped by a JTAtransaction. The processing here is exactly the same as in the older JTA-only approach. See the Javadocs for details. org.hibernate.context.internal.ThreadLocalSessionContext:current sessions are tracked by thread of execution. See the Javadocs for details. org.hibernate.context.internal.ManagedSessionContext: current sessions are tracked by thread of execution. However, you are responsible to bind and unbind a Session instance with static methods on this class: it does not open, flush, or close a Session.
hibenate. current 를 설정 해 야 합 니 다.session_context_class 는 jta 이 며, 동시에 hibenate. transaction. manager 를 설정 합 니 다.lookup_class。그런데 여기 서 한참 을 지체 한 게 바로 히 베 네 이 트. transaction. manager 입 니 다.lookup_class 의 설정 은 "설정 이 필요 합 니 다" 라 고 만 말 하지만 구체 적 인 값 은 제시 되 지 않 았 습 니 다. 문서 에 Transaction Manager Lookup 인터페이스의 실현 클래스 목록 이 있 지만 Glassfish 도 없습니다. N 오래된 구 글 을 거 쳐 여기 서 신기 한 실현 클래스 를 찾 았 습 니 다. org. hibenate. transaction. sunonetransaction. sunonetransaction Manager Lookup.Javadoc 에 따 르 면 'for Sun ONE Application Server 7 and above' 의 검색 전략 을 실 현 했 습 니 다. GF 의 전신 이 Sun AS 라 고 생각해 보 세 요. 사용 할 수 있 을 것 같 습 니 다.해 보 니 워 크 ~ 여기 남 겨 진 문 제 는 하 이 버 네 이 트 4.1.1 소스 코드 에서 org. hibenate. transaction. sunonetransaction. sunonetransaction Manager Lookup (위의 자바 doc 도 3.6 의 자바 doc) 을 찾 지 못 했 고 심지어 전체 org. hibenate. transaction 패키지 아래 에는 Transaction Manager Lookup 인터페이스 만 정의 되 어 있 습 니 다.그래서 도대체 어떻게 작 동 하 는 지 저 는 최종 답 을 찾 지 못 했 습 니 다. 만약 에 아 는 사람 이 있다 면 여기 서 답 을 남 겼 으 면 좋 겠 습 니 다. 2012 - 4 - 16 보: 오늘 서버 를 시작 할 때 우연히 warning, hibenate. transaction. manager 를 던 진 것 을 발 견 했 습 니 다.lookup_class 는 Hibernate 4 에서 deprecated 되 었 습 니 다.
1
hibernate.transaction.jta.platform=
org. hibernate. service. jta. platform. internal. sunOne Jta Platform 을 사용 해 야 합 니 다.
2012 - 4 - 17 보충: 오늘 Hibernate 의 자동 flush 가 실 효 된 것 을 발 견 했 습 니 다. GF 시작 로 그 를 보고 새로운 warning 을 발 견 했 습 니 다.
JTASessionContext being used with JDBCTransactionFactory; auto-flush will not operate correctly with getCurrentSession()
문 서 를 찾 아 보 니 위의 1, 2 곳 에 TransactionFactory 를 지정 해 야 합 니 다. 그렇지 않 으 면 Hibernate 는 JDBCtransactionFactory:
1
hibernate.transaction.factory_class=
org. hibernate. transaction. JTaTransactionFactory 를 기본적으로 사용 합 니 다.
문제 해결.이번 경험 역시 app server 가 시 작 될 때 대량의 log 를 출력 하지만 그 중에서 warning 등급 과 이상 의 정 보 를 발견 하 는 통찰력 을 키 워 야 합 니 다. 이렇게 문 제 를 해결 하 는 데 적은 노력 으로 큰 효 과 를 거 둘 것 입 니 다. 2012 - 4 - 22 보충: 오늘 또 문제 가 생 겼 습 니 다. Query. iterate () 방법 을 사용 할 때 Hibernate 는 이상 을 던 집 니 다.
org.hibernate.HibernateException: proxy handle is no longer valid
여기 서 의 토론 에 따 르 면 JTA Transaction Factory 를 CMTTransaction Factory 로 바 꾸 었 습 니 다. 문제 해결:
1
hibernate.transaction.factory_class=
org. hibenate. transaction. CMT TransactionFactory
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
다양한 언어의 JSONJSON은 Javascript 표기법을 사용하여 데이터 구조를 레이아웃하는 데이터 형식입니다. 그러나 Javascript가 코드에서 이러한 구조를 나타낼 수 있는 유일한 언어는 아닙니다. 저는 일반적으로 '객체'{}...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.