Results 1 to 4 of 4

Thread: transaction mgmt for Hibernate managed objects

  1. #1
    Join Date
    Aug 2004
    Posts
    1

    Default transaction mgmt for Hibernate managed objects

    is it possible to add declarative transaction management using the TransactionProxyFactoryBean class to Hibernate managed objects?

    Example will be appreciated.. or any documentation??

  2. #2
    Join Date
    Aug 2004
    Location
    Brno, Czech Republic
    Posts
    48

    Default

    This doesn't make sense to me. It is usually necessary to run service (and/or Hibernate DAO methods) transactionally. Those services (and also DAOs) are declared as singleton beans in Spring's application context and it can easily became transactional using TransactionProxyFactoryBean .

    But why to apply transaction management to Hibernate managed objects?

  3. #3
    Join Date
    Aug 2004
    Location
    San Mateo, CA
    Posts
    1,265

    Default

    What would happen to the Hibernate Session if you were to transactionally advise an operation on a persistent object? I'm finding it hard to think of a valid use case.
    Rod Johnson - GM, SpringSource Division, VMware
    http://www.springsource.com
    Spring From the Source

  4. #4
    Join Date
    Aug 2004
    Posts
    109

    Default

    the valid use case would be a case where you construct a rich domain model and instead of facading it with a service allow client interact with it directly. So for example, suppose you have an Applicant and Address objects as part of your domain model, and applicant can have multiple addresses, so you can add an address. Now there are two ways of making it happen:

    1. Create Facade and have a method add (Applicant a, Address addr) that will actualy be transactional method that will take care of adding an address to the applicant's record. Facade is the service (bean) managed by spring, hence making add transactional is not a problem.

    2. Have a method on Applicant object that would be add (Address). This however will have to be somehow talking back to spring to take care of transactions for me. Note also Applicant can not be a spring managed service since hibernate is probably the one that creates it.

    While method 1 is acceptable the method 2 is more natural. So if I develop domain model for someone else to use (in presentation tier) I would rather employ method 2, because there is less stuff to get confused about and hence for me to explain to people.

    Anyway to make long story short, the way to deal with the problem, in my opinion, is to use AspectJ in conjunction with spring. The major reason for using AspectJ is that you can not inject spring's capabilities into something that is not managed by spring (in this case the classes are managed by hibernate). So you will have to precompile into hibernate managed classes the awareness of Spring thru AspectJ aspects.
    Thanks,
    Alex.

Similar Threads

  1. Unit testing with JOTM and JtaTransactionManager
    By lalle in forum Architecture
    Replies: 1
    Last Post: Oct 15th, 2005, 09:05 AM
  2. Replies: 3
    Last Post: May 16th, 2005, 07:04 AM
  3. Replies: 3
    Last Post: Nov 19th, 2004, 07:16 PM
  4. Replies: 8
    Last Post: Sep 23rd, 2004, 01:12 AM
  5. Transaction pb Hibernate/MySQL
    By syluser in forum Data
    Replies: 2
    Last Post: Aug 28th, 2004, 02:40 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •