java ee - Hibernate use openConnection inside Transaction and use getCurrentSession outside of Transaction -
i learning hibernate recently, gives me lot of headache, have been using datasource.getconnection
while in application, learning session
concept in hibernate quite difficult. can't find enough information or confirmed information api/doc too.
i have read through this. understand if have container managed transaction (i using hibernatetransactionmanager
, spring's transactional
annotation), of time, supposed use getcurrentconnection
(inside transaction), in return me connection bound transaction context.
but sometime have use other people method/code/library/framework possibly inside using openconnection
(i not able change code), know, consequence of doing this? connection obtained in way same session getcurrentconnection
(since called inside transaction)? or different? if different, bind transaction , managed transaction too? while "managed by" meaning, transaction context set auto-commit false
, upon transaction.commit
, transaction commit changes (might rollback too)?
it extends thought, if called getcurrentconnection
outside of transaction? there no transaction context, connection being returned? , connection bound to? based on doc, can see doing valid, doesn't explain consequence.
but sometime have use other people method/code/library/framework possibly inside using
openconnection
(i not able change code), know, consequence of doing this?
ok have tested code above, create new hibernate session, mean, have manually handle session, include close , flush it.
it extends thought, if called getcurrentconnection outside of transaction?
this totally no working, throw exception because can't find active transaction outside transaction block.
Comments
Post a Comment