facebook

Add Spring + Hibernate support to MyEclipse?

  1. MyEclipse IDE
  2.  > 
  3. Feature Requests
Viewing 15 posts - 1 through 15 (of 67 total)
  • Author
    Posts
  • #211423 Reply

    Thomas Trostel
    Participant

    For those of you who haven’t seen Spring before there is a very good introduction located at http://www.theserverside.com/articles/article.tss?l=SpringFramework.

    Spring is a lightweight framework that sits somewhere short of a full blown J2EE deployment and is also extremely modular. It has been broken into 7 distinct modules:

    – Core: supporting utilities and their own bean container
    – AOP: source level meta-data and AOP (Aspect Oriented Programming) interface
    – ORM: (Object Relational Mapping) with support for Hibernate, iBaits, and JDO
    – DAO: Transaction infrastructure with JDBC and DAO support.
    – Web: Web/Application Context, Multi-Part resolver, and web utilities
    – Context: Application Context, UI support, validation, JNDI, EJB (support & remoting), mail
    – Web MVC: Web Views JSP/Velocity/PDF/Excel

    There is a lot in there … the pieces of interest in this context are the ORM and DAO components. Looking on the web there is a rudimentary Spring IDE plug in for Eclipse already but it measures up fairly short in terms of leaving the user with a starting template from which to build a project. We’d honestly be looking for the higher level transaction support.

    #211581 Reply

    Ivar Vasara
    Member
    #211586 Reply

    Riyad Kalla
    Member

    Well this seems to be getting to be a popular request. Keep voting guys.

    #211636 Reply

    Thomas Trostel
    Participant

    I was surprised nobody had mentioned it before. Part of the attention may be due to the new O’Reilly book “Better, Faster, Lighter Java” by Bruce A. Tart and Justin Gehtland. I’m planning on getting a copy this weekend if its in our local bookstore.

    #211644 Reply

    grimholtz
    Member

    Don’t forget to get the Spring bible, “J2EE Development Without EJB” by Mr. and Mrs. Spring themselves — Rod Johnson and Juergen Hoeller.

    #211651 Reply

    Ivar Vasara
    Member

    @ttrostel wrote:

    I was surprised nobody had mentioned it before. Part of the attention may be due to the new O’Reilly book “Better, Faster, Lighter Java” by Bruce A. Tart and Justin Gehtland. I’m planning on getting a copy this weekend if its in our local bookstore.

    I had that book for all of two days before returning it. It seemed like a nicely edited blog.. a little bit of this and a little bit of that. I was looking for a discussion of lightweight practices & tools and found BFL Java to be somewhat weak.. “J2EE development without ejb” on the other hand, far exceeded my expectations. It starts a little slowly, bordering on ranting against EJB.. but as the it progresses it gets better. I found the testing chapter to be particularly fantastic and is almost worth the price of the book itself … quite odd since I had every intention of skipping the chapter when I bought the book. I’d highly recommend it over BLFJ..

    #211684 Reply

    Thomas Trostel
    Participant

    Thanks … I took a look at it in the bookstore this weekend fully expecting to buy it. After flipping through it I wasn’t that impressed. Unfortunately they didn’t have the “J2EE development without EJB” book on the shelf to peruse.

    I spent the money on a hot cup of Starbucks coffee instead while looking for other things.

    Thanks for the heads up.

    #211691 Reply

    Riyad Kalla
    Member

    I spent the money on a hot cup of Starbucks coffee instead while looking for other things.

    That’s an expensive cup of coffee… 🙂

    What I would appreciate from you Spring guys is to comment (as you learn Spring) on the types of things you want animated. Considering that no one on our team has experience with Spring, its tough for us to figure out (by staring at the framework) what we can automate.

    So if you could give comments like “In spring there is the idea of mapping configs, these are generated by BLAH, it would be nice if BLAH BLAH”, something like that, to give us an idea.

    I’m asking now because clearly Spring is popular and only more and more people will want support for it, so we might as well start collecting ideas now.

    #211741 Reply

    Thomas Trostel
    Participant

    Aha … touche’

    First to create the Spring DAO mapping and transactional stuff you’re going to need the following libraries included in your project build:

    spring-core.jar – Base functionality for the Spring framework
    spring-dao.jar – Data Access Object stuff
    spring-orm.jar – Object Relational Management stuff

    There are two base factories we would be interested in from a configuration standpoint, the BeanFactory and the ConfigurationFactory … lets concentrate on the BeanFactory first.

    Now … right now we’re creating a HibernateSessionFactory class configured with hibernate.hbm.xml to start up the framework. That would get wrapped by Spring so we need to move the elements into their bean factory. The particular configuration we are testing uses the XmlBeanFactory class as a starting point for a stand alone java aplication.

    Instantiating the bean factory in this case is as simple as:

    =====

    // Initialize the bean factory with the worlds simplest bean
    InputStream is = null;

    try {
    is = new FileInputStream(directory + “/beans.xml”);
    } catch (FileNotFoundException e) {
    logger.error(e.getMessage());
    e.printStackTrace();
    }

    XmlBeanFactory factory = new XmlBeanFactory(is);

    =====

    The bean XML file needs to have a reference to the data source, session factory, transaction manager, and whatever services you are interested in. Here is a sample:

    =====

    <?xml version=”1.0″ encoding=”UTF-8″?>
    <!DOCTYPE beans PUBLIC “-//SPRING//DTD BEAN//EN” “http://www.springframework.org/dtd/spring-beans.dtd”&gt;

    <beans>
    <description>Spring Sample Beans Configuration</description>

    <bean id=”dataSource”
    class=”org.apache.commons.dbcp.BasicDataSource” destroy-method=”close”>
    <property name=”driverClassName”><value>oracle.jdbc.driver.OracleDriver</value></property>
    <property name=”url”><value>jdbc:oracle:thin:@some.server.org:1521:oracle_sid</value></property>
    <property name=”username”><value>USER</value></property>
    <property name=”password”><value>PASS</value></property>
    </bean>

    <bean id=”sessionFactory”
    class=”org.springframework.orm.hibernate.LocalSessionFactoryBean”>
    <property name=”dataSource”><ref local=”dataSource”/></property>
    <property name=”mappingResources”>
    <list>
    <value>com/ttrostel/spring/hibernate/SomeObject.hbm.xml</value>
    </list>
    </property>
    <property name=”hibernateProperties”>
    <props>
    <prop key=”hibernate.dialect”>net.sf.hibernate.dialect.Oracle9Dialect</prop>
    </props>
    </property>
    </bean>

    <bean id=”transactionManager”
    class=”org.springframework.orm.hibernate.HibernateTransactionManager”>
    <property name=”sessionFactory”><ref local=”sessionFactory”/></property>
    </bean>

    <bean id=”objectService” class=”com.ttrostel.spring.ObjectService”>
    <property name=”sessionFactory”>
    <ref bean=”sessionFactory”/>
    </property>
    </bean>
    </beans>

    ======

    Looks very similar to the hibernate.hbm.xml which would be easy to parse and keep in sync

    in the implementation … again stand alone …

    we can get an instance of the object service as follows:

    ====

    ObjectService myObjectSrv = (ObjectService) factory.getBean(“objectService”);

    ====

    then you can pretty much go ahead and use the service at will .. for example

    ====

    List liSomething = myObjectSrv.getSomethinById(“123”);

    ====

    and ObjectService would look like this

    ====

    public class ObjectService extends HibernateDaoSupport{

    /** Find all the things matching a given string
    * @param strId
    * @return
    */
    public List getSomethinById(String strId) {

    return getHibernateTemplate().find(“from Something as thing where thing.id = ?”,
    strId, Hibernate.STRING);
    }

    ====

    Transactional boundries are defined in the bean XML file and are by service bean. You can demarcate which other beans participate in each transactions and if the transaction should be propogated.

    …. not sure if thats a good starting point or not. We’ll try to keep you updated as we progress.

    Please excuse the disorganized thought process … we’re trying to get a good handle on it ourselves.

    #211820 Reply

    See the https://appfuse.dev.java.net/ for lots of Hibernate, Struts, Spring, etc integration.

    #211928 Reply

    Thomas Trostel
    Participant

    Hmm … that looks pretty nifty … wonder if that could be folded in as a wizard starting project.

    #212082 Reply

    grfyljq
    Member

    Thanks for listening to the many posts about this issue including mine:
    https://www.genuitec.com/forums/topic/the-accenture-bellsouth-wishlist/&start=0&postdays=0&postorder=asc&highlight=spring+hibernate
    I will definitely be renewing my subscription and recommending this to all my colleagues.

    #212084 Reply

    Scott Anderson
    Participant

    Well thank you very much! We always appreciate user feedback and enhancement suggestions. Version 3.8 GA will have greatly improved hibernate support over Beta 2, so we hope you like it. If not, I’m sure we’ll get some constructive feedback. 😉

    #212089 Reply

    Brian Lee
    Member

    I definitely like the direction MyEclipse is taking – adding Spring support is a great!

    @awf999 wrote:

    See the https://appfuse.dev.java.net/ for lots of Hibernate, Struts, Spring, etc integration.

    Yeah, I agree – AppFuse is definitely worth taking a look at since it is basically a project that integrates Spring, Struts/Webwork, Hibernate/Ibatis. No need to reinvent the wheel.

    #212229 Reply

    rmwilliams4
    Member

    I cast a vote for Spring support. In particular it would be nice when using Hibernate if the config stuff could be located inside a Spring config file instead of a hibernate.properties or hibernate.hbm.xml file.

    Also a graphical view of the AOP stuff in Spring would be cool – similar to the interface presented by AspectJ in Eclipse.

    Thanks for a great product.

Viewing 15 posts - 1 through 15 (of 67 total)
Reply To: Add Spring + Hibernate support to MyEclipse?

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