`
semi_sleep
  • 浏览: 99425 次
  • 性别: Icon_minigender_1
  • 来自: 广州
社区版块
存档分类
最新评论

Note for hibernate 2009.1.8 - 2009.1.13

阅读更多

1. When automatic versioning is used, hibernate generates the following sql:

update products set version=?, name=?, description=?, unitCost=?, pubTime=where id=and version=?

Note that using such sql, you don't need to select the version from database to compare with current version.

2. Other ways to resolve LazyInitializationException, except Open Session in View.

3. Note that for the Transaction in jta, you can register a Synchronization, through this you can be informed before or aftter transaction commit, is Hibernate use this way to flush?

Confirmed that hibernate will register a Synchronization to JTA Transaction.

 

4. Hibernate3 use event-listener pattern to implement varied operations (like save(), update()...)

 

5. There are 3 transaction release mode : after statement, after transaction (default since 3.2), on close (after session close). Note that though connection is released "after transaction", it has no impact on lazy load, it just starts a new transaction.

 

6. TransactionFactory.Context (actually a session), JDBCContext are context for Transaction, which contains Transaction instance and provide methods for Transaction to call (callback). JDBCContext.Context (actually a session) are context for JDBCContext.

JDBCContext is also used by Session to delegate method calls for transaction and connection management.

 

7. SessionImpl can be nested in tree style, and they share the same timestamp, jdbcContext, interceptor and listeners.

 

8. Who calls TransactionFactory.Context and JDBCContext's before/after method? Both CacheSynchronization and Transaction will do.

 

9. Can I call the save() method without starting a new transaction? Yes, in case of JTA or CMT, the transaction is already started, for JDBC, it also starts a new transaction for JDBC dose not need to call a begin() method.

 

10. Why jta transaction and jdbc transaction's code style should be different? Hibernate provides JTA/CMT Transaction in order to support change to use JTA/CMT from JDBC without code change, so JTA and CMT can use JDBC transaction style, also, they can use their own style.

 

11. Explain JDBCContext's registerCallbackIfNecessary() and registerSynchronizationIfPossible() method. A callback is needed in order to flush before transaction commit, this callback can either be CacheSynchronization that register itself to jta transaction, or hibernate's JDBC/JTA/CMT Transaction. The registerSynchronizationIfPossible() method use CacheSynchronization, while registerCallbackIfNecessary() use hibernate's transaction object. The registerCallbackIfNecessary() method return true if callback is needed, if registerSynchronizationIfPossible() or registerCallbackIfNecessary() was called before, it will return false.

 

12. Those TransactionManagerLookup implementations are used by JTATransactionManager and also SessionFactoryImpl (whose getTransactionManager() method is used by JDBCContext's registerSynchronizationIfPossible()).

 

13. Can omit flush and close session before JTA transaction commit? I believe not, when transaction commit, session will flush and at that time session is closed, but still need to test.
Also, dose jta transaction need to begin before opening a new session? I believe not too.

 

14. Can omit hibernate.transaction.factory_class setting? If incorrect factory class is specified, Interceptor will get incorrect type of Transaction and fail to retrieve correct state from that transaction. If hibernate transaction objects are used by client code, incorrect factory class will cause error.

 

15. How hiberate detect the type of transaction to use automatically? Hibernate will first try to find out whether a callback is registered and use TransactionManager to see if there's currently a transaction, if yes, it will register a synchronization, if no, it will rely on client code to call hibernate's transaction objects.

 

16. Relationship between TransactionFactory, Transaction, TransactionManagerLookup, CacheSynchronization, JDBCContext, Interceptor.





  

 

- -! Gavin King 's comment at TransactionManagerLookup.getTransactionIdentifier: "This method was added specifically for use in WebSphere and other unfriendly JEE containers (although WebSphere is still the only known such brain-dead, sales-driven impl)."

  • 大小: 8.7 KB
  • 大小: 15.7 KB
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics