facebook

SPRING and Hibernate Reverse Engineering – SUGGESTION

  1. MyEclipse IDE
  2.  > 
  3. Spring Development
Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #309941 Reply

    adrian.challinor
    Participant

    Withe MyEcipse for Spring (ME4S) it should be very easy to add transaction management as a Spring generated AOP. It is really simple in principal…. but it took me several hours to figure out how to do it with MR4S and Hibernate Reverse Engineering.

    This is not a change to way that the application context is created (I can post mine if people wish). The issue is that HRE creates the DAO classes as base classes. Spring really needs these to be implementations and classes. That way, Spring AOP can generate the proxies classes on the fly, but you need never know.

    The suggestion is to add a new flag to the HRE section “Java Data Access Only (DAO)” section, to indicate that you want Spring Transactional Management. What this would do is:

    a) Create the MyObjectDAO as an interface

    b) Create the MyObjectDAOImpl as a class, implementing MyObjectDAO

    c) Before the Save() and Delete() methods, add the annotation “@Transactional”

    d) When it inserts in to the application context XML file, add the phrase:

        <bean id = "MyObjectDAO" class="mypackage.MyObjectDAOImpl">
             <property name="sessionFactory">
                <ref bean="sessionFactory" />
            </property>
        </bean>
    

    All the user needs to do is then extend the Application Context XML file to include transaction annotations support and a transactional manager, but that can and should be left to the user. Mine looks like this….

     <!-- enable the configuration of transactional behavior based on annotations -->
      <tx:annotation-driven transaction-manager="txManager"/>
    
        <!-- don't forget the PlatformTransactionManager -->
        <bean id="txManager"
            class="org.springframework.orm.hibernate3.HibernateTransactionManager">
            <property name="sessionFactory">
                <ref local="sessionFactory" />
            </property>
        </bean>
    

    The benefit is that the user of ME4S can now generate the DAO layer via reverse engineering and expect it to work out of the box. There is no longer any need to ever handle the transaction layer in the POJO or its callier.

    Just a suggestion….!

    #310030 Reply

    Heflin Hogan
    Member

    Thank you for the feedback! It’s always nice to hear from folks who’ve taken enough interest in the product to post.

    With regards to your suggestion, are you aware that the scaffolding functionality in MyEclipse for Spring builds transaction management functionality into the generated framework? The quick start tutorial at http://www.myeclipseide.com/documentation/quickstarts/scaffoldingtutorial/scaffolding.html walks through the process. You can check out the generated Spring configuration for the DAO in the project’s resources folder. It will be named customersapp-generated-dao-context.xml, if you followed the tutorial.

    Out of curiosity, are you using the ME4S 8.5 release, or the 8.6 preview?

    Regards,
    Heflin

    #310032 Reply

    adrian.challinor
    Participant

    Heflin

    Hi – yes I am aware of the scaffolding part. Thats great if you are building a web application. Spring. as a framework, does not predicate a web application. My particular project is a server based application – I just wanted to use the AOP and DI parts of Spring to make the objects as simple as possible.

    Adrian

    #310033 Reply

    Heflin Hogan
    Member

    Adrian,

    You don’t have to scaffold the entire web application. If you just wanted the DAO, on the Application Layers and Packages panel of the scaffolding wizard, you would uncheck the web and service layers. While the default is to scaffold an entire web app, we’ve attempted to provide as much flexibility as possible. You might also want to check out the ME4S 8.6 preview. We’ve added more functionality to assist in the development of Spring applications.

    Regards,
    Heflin

    #310062 Reply

    adrian.challinor
    Participant

    Heflin,

    Actually, that is pretty neat. Very nice indeed actually. Thank you.

    On teeny comment – even if you uncheck “Scaffold Web Layer” the Scaffold wizard still requires a web folder. But I can live with that!

    Thanks

    Adrian

Viewing 5 posts - 1 through 5 (of 5 total)
Reply To: SPRING and Hibernate Reverse Engineering – SUGGESTION

You must be logged in to post in the forum log in