-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 10 posts ] 
Author Message
 Post subject: Seeking advice on Hibernate tools
PostPosted: Thu Sep 18, 2008 6:01 am 
Beginner
Beginner

Joined: Thu Sep 18, 2008 5:18 am
Posts: 28
Hello good people.. Am a newbie here, actually am new to lots of things including Java, J2EE tools/Frameworks .. I have now for the past two months being going through a lot of study material which include the following

1. JSP/Servelts/EJBs - good understanding
2. Struts framework - very good understanding
3. Hibernate - busy, but good background
4. Middlegen - a little confused
5. Spring - going through now and seems usefull for reverse engineering
6. XDoclet - completely confused

My Questions/Scenario

Here at work we strictly use the struts framework, and all the existing web application are written on this framework. I am tasks to learn in practice about Hibernate because it will make things easier and we will use it with the struts framework. Now after reading through the above, i'm confused as to what goes with what! There's a tutorial which combines Hibernate+Spring+XDoclet+Middlegen ...
Q.
1. In this case, maybe in brief, what is the use of each in this combination?
2. What does reverse engineering? Is it Hibernate, or Spring or/and Middlegen
3. Which is the better choice between Struts and Spring or can they be used together?
4. Lastly, What is a disadvantage of just using Hibernate with struts without involving/adding Spring or middlegen into it

Hope my confusion is clearly put.. I look forward to good maybe brief answers .. Yes i have gone through these but each document containts tons of pages which i may not have time to read and understand within the time space i'm given... So, i'll be happy if you don't refer me to yet another big doc on either of the above

thnx in advance


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 19, 2008 7:54 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
I don't get why you thing Spring is useful for reverse engineering ? It doesn't do that ;)

Middlegen and Hibernate tools are the parts that does reverse engineering.

In any case your question is very broad and I can't really answer this with a simple forum posting. But let me try:


1) I would not look at XDoclet/Middlegen if you are starting a new project.
Look into EJB3/JPA instead and see how to use Java5 Annotations to avoid
alot of the code generation that was needed in the "old days" of xdoclet/j2ee1.4

2) MiddleGen and Hibernate tools does the reverse engineering.
Spring has nothing to do with this. MiddleGen is a general purpose reverse engineering tool which havent seen much maintanence the last couple of years. We (Hibernate team) maintain Hibernate Tools for doing Hibernate related reverse engineering.

3) Struts is a webframework, Spring is not. They can be used together.
Have you looked at JBoss Seam ?

4) There is no disadvantage. You get to use the Hibernate API directly (which is a good thing) and if you don't use reverse engineering you get to control how the mapping is done.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 19, 2008 11:03 am 
Beginner
Beginner

Joined: Thu Sep 18, 2008 5:18 am
Posts: 28
max wrote:
I don't get why you thing Spring is useful for reverse engineering ? It doesn't do that ;)

Middlegen and Hibernate tools are the parts that does reverse engineering.

In any case your question is very broad and I can't really answer this with a simple forum posting. But let me try:


1) I would not look at XDoclet/Middlegen if you are starting a new project.
Look into EJB3/JPA instead and see how to use Java5 Annotations to avoid
alot of the code generation that was needed in the "old days" of xdoclet/j2ee1.4

2) MiddleGen and Hibernate tools does the reverse engineering.
Spring has nothing to do with this. MiddleGen is a general purpose reverse engineering tool which havent seen much maintanence the last couple of years. We (Hibernate team) maintain Hibernate Tools for doing Hibernate related reverse engineering.

3) Struts is a webframework, Spring is not. They can be used together.
Have you looked at JBoss Seam ?

4) There is no disadvantage. You get to use the Hibernate API directly (which is a good thing) and if you don't use reverse engineering you get to control how the mapping is done.


Thnx for you time Max, very helpful indeed ...

I went thru a tutorial Hibernate+Spring .. Would you say using hibernate & spring is good enough to develop Web Based appliations ...

This is what i've learned from the tutorial

1. Reverse Engineering (Code generation from existing tables) using Hibernate.. Very powerful indeed

2. Mapping of beans to with DB tables : Again hibernate

3. Persistence Layer (not sure but i think it means the changes happening on the table are directly mapped to the beans) .. Aigain, hibernate plays a role here

4. Now, The generation of the of beanname.hbm.xml is achieved using spring, am i'm correct

5. Also, the beanDAO is handled by Spring .

Otherwise please explain the use of Spring in my scenario ....

Thanx once more :)


Top
 Profile  
 
 Post subject:
PostPosted: Sat Sep 20, 2008 6:09 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
Which tutorial are you looking at ? It seems you are the article has some concepts mixed up ;)

About 4 generation of hbm.xml is acheived using spring I can't see how that should occur. Spring might tell Hibernate where the hbm.xml is, but Spring did not generate it.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 22, 2008 5:48 am 
Beginner
Beginner

Joined: Thu Sep 18, 2008 5:18 am
Posts: 28
max wrote:
Which tutorial are you looking at ? It seems you are the article has some concepts mixed up ;)

About 4 generation of hbm.xml is acheived using spring I can't see how that should occur. Spring might tell Hibernate where the hbm.xml is, but Spring did not generate it.


Here ...

http://www.myeclipseide.com/documentati ... andspring/

P.S Please note that the tutorial maybe correct, but i could have miss-interpreted it... I'm still learning so not sure 100% the use of hibernate and Spring in this tutorial ... perhaps if you have time to look at it and explain to me as to what are these two tools used for will be of great honor.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 24, 2008 3:31 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
you do know this is a MyEclipse based tutorial ? MyEclipse does contain a version of Hibernate Tools but they forked it so i'm not sure what works and what does not work in their setup.

In any case, their tutorial looks correct, but I don't see why you view Spring as the part that is reverse engineering ;)

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 25, 2008 4:16 am 
Beginner
Beginner

Joined: Thu Sep 18, 2008 5:18 am
Posts: 28
max wrote:
you do know this is a MyEclipse based tutorial ? MyEclipse does contain a version of Hibernate Tools but they forked it so i'm not sure what works and what does not work in their setup.

In any case, their tutorial looks correct, but I don't see why you view Spring as the part that is reverse engineering ;)


Hi Max, i now have a better understanding between the two... You say the tutorial works, does this mean you've tried it? If so, i have a question!!

The following code does not compile on my side

Code:
package com.myeclipse.hibernatespring;

public class BusinessLogic {
    public static void main(String[] args) {
        /* 1. Create a new user */
        Integer id = new Integer(1);
        User user = new User();
        user.setId(id);
        user.setUsername("jdoe");
        user.setPassword("1234");
        user.setFirstName("John");
        user.setLastName("Doe");
        user.setDateCreated(Long.valueOf(System.currentTimeMillis()));

        /* 2. Load the Spring bean configuration and create a bean factory */
        BeanFactory beanFactory = new XmlBeanFactory(new ClassPathResource(
                "applicationContext.xml"));

        /* 3. Create instance of PersistenceLayer */
        PersistenceLayer persistenceLayer = (PersistenceLayer) beanFactory
                .getBean("persistenceLayer");

        /* 4. Save the new user to the database */
        persistenceLayer.addUser(user);

        /* 5. Confirm that our user was saved */
        User userLoadedFromDB = persistenceLayer.findUserById(id);
        System.out.println("User Loaded from DB [username="
                + userLoadedFromDB.getUsername() + ", password="
                + userLoadedFromDB.getPassword() + ", firstName="
                + userLoadedFromDB.getFirstName() + ", lastName="
                + userLoadedFromDB.getLastName() + "]");

        /* 6. Update the user */
        userLoadedFromDB.setFirstName("Johnathan");
        persistenceLayer.updateUser(userLoadedFromDB);

        /* 7. Confirm that the update worked */
        User userLoadedFromDBAgain = persistenceLayer
                .findUserById(id);
        System.out.println("User Loaded from DB Again [firstName="
                + userLoadedFromDBAgain.getFirstName() + "]");

        /* 8. Delete the user */
        persistenceLayer.deleteUser(user);
    }
}


I get an error on the this line ...
Code:
        BeanFactory beanFactory = new XmlBeanFactory(new ClassPathResource(
                "applicationContext.xml"));


Says BeanFactory cannot be resolved to a type .. Goes the same with XmlBeanFactory ... To solve this, i have to import the BeanFactory classes from org.springframework ... But when i run the program, i get an ClassNotFound exception ... class being "LogFactory" ... I have added commons-logging.jar to my build path ... I think this has to do with me importing BeanFactory hence the author didn't ....

How did you bypass this?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 25, 2008 4:17 am 
Beginner
Beginner

Joined: Thu Sep 18, 2008 5:18 am
Posts: 28
max wrote:
you do know this is a MyEclipse based tutorial ? MyEclipse does contain a version of Hibernate Tools but they forked it so i'm not sure what works and what does not work in their setup.

In any case, their tutorial looks correct, but I don't see why you view Spring as the part that is reverse engineering ;)


Hi Max, i now have a better understanding between the two... You say the tutorial works, does this mean you've tried it? If so, i have a question!!

The following code does not compile on my side

Code:
package com.myeclipse.hibernatespring;

public class BusinessLogic {
    public static void main(String[] args) {
        /* 1. Create a new user */
        Integer id = new Integer(1);
        User user = new User();
        user.setId(id);
        user.setUsername("jdoe");
        user.setPassword("1234");
        user.setFirstName("John");
        user.setLastName("Doe");
        user.setDateCreated(Long.valueOf(System.currentTimeMillis()));

        /* 2. Load the Spring bean configuration and create a bean factory */
        BeanFactory beanFactory = new XmlBeanFactory(new ClassPathResource(
                "applicationContext.xml"));

        /* 3. Create instance of PersistenceLayer */
        PersistenceLayer persistenceLayer = (PersistenceLayer) beanFactory
                .getBean("persistenceLayer");

        /* 4. Save the new user to the database */
        persistenceLayer.addUser(user);

        /* 5. Confirm that our user was saved */
        User userLoadedFromDB = persistenceLayer.findUserById(id);
        System.out.println("User Loaded from DB [username="
                + userLoadedFromDB.getUsername() + ", password="
                + userLoadedFromDB.getPassword() + ", firstName="
                + userLoadedFromDB.getFirstName() + ", lastName="
                + userLoadedFromDB.getLastName() + "]");

        /* 6. Update the user */
        userLoadedFromDB.setFirstName("Johnathan");
        persistenceLayer.updateUser(userLoadedFromDB);

        /* 7. Confirm that the update worked */
        User userLoadedFromDBAgain = persistenceLayer
                .findUserById(id);
        System.out.println("User Loaded from DB Again [firstName="
                + userLoadedFromDBAgain.getFirstName() + "]");

        /* 8. Delete the user */
        persistenceLayer.deleteUser(user);
    }
}


I get an error on the this line ...
Code:
        BeanFactory beanFactory = new XmlBeanFactory(new ClassPathResource(
                "applicationContext.xml"));


Says BeanFactory cannot be resolved to a type .. Goes the same with XmlBeanFactory ... To solve this, i have to import the BeanFactory classes from org.springframework ... But when i run the program, i get an ClassNotFound exception ... class being "LogFactory" ... I have added commons-logging.jar to my build path ... I think this has to do with me importing BeanFactory hence the author didn't ....

How did you bypass this?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 25, 2008 4:20 am 
Beginner
Beginner

Joined: Thu Sep 18, 2008 5:18 am
Posts: 28
max wrote:
you do know this is a MyEclipse based tutorial ? MyEclipse does contain a version of Hibernate Tools but they forked it so i'm not sure what works and what does not work in their setup.

In any case, their tutorial looks correct, but I don't see why you view Spring as the part that is reverse engineering ;)


Hi Max, i now have a better understanding between the two... You say the tutorial works, does this mean you've tried it? If so, i have a question!!

The following code does not compile on my side

Code:
package com.myeclipse.hibernatespring;

public class BusinessLogic {
    public static void main(String[] args) {
        /* 1. Create a new user */
        Integer id = new Integer(1);
        User user = new User();
        user.setId(id);
        user.setUsername("jdoe");
        user.setPassword("1234");
        user.setFirstName("John");
        user.setLastName("Doe");
        user.setDateCreated(Long.valueOf(System.currentTimeMillis()));

        /* 2. Load the Spring bean configuration and create a bean factory */
        BeanFactory beanFactory = new XmlBeanFactory(new ClassPathResource(
                "applicationContext.xml"));

        /* 3. Create instance of PersistenceLayer */
        PersistenceLayer persistenceLayer = (PersistenceLayer) beanFactory
                .getBean("persistenceLayer");

        /* 4. Save the new user to the database */
        persistenceLayer.addUser(user);

        /* 5. Confirm that our user was saved */
        User userLoadedFromDB = persistenceLayer.findUserById(id);
        System.out.println("User Loaded from DB [username="
                + userLoadedFromDB.getUsername() + ", password="
                + userLoadedFromDB.getPassword() + ", firstName="
                + userLoadedFromDB.getFirstName() + ", lastName="
                + userLoadedFromDB.getLastName() + "]");

        /* 6. Update the user */
        userLoadedFromDB.setFirstName("Johnathan");
        persistenceLayer.updateUser(userLoadedFromDB);

        /* 7. Confirm that the update worked */
        User userLoadedFromDBAgain = persistenceLayer
                .findUserById(id);
        System.out.println("User Loaded from DB Again [firstName="
                + userLoadedFromDBAgain.getFirstName() + "]");

        /* 8. Delete the user */
        persistenceLayer.deleteUser(user);
    }
}


I get an error on the this line ...
Code:
        BeanFactory beanFactory = new XmlBeanFactory(new ClassPathResource(
                "applicationContext.xml"));


Says BeanFactory cannot be resolved to a type .. Goes the same with XmlBeanFactory ... To solve this, i have to import the BeanFactory classes from org.springframework ... But when i run the program, i get an ClassNotFound exception ... class being "LogFactory" ... I have added commons-logging.jar to my build path ... I think this has to do with me importing BeanFactory hence the author didn't ....

How did you bypass this?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 25, 2008 6:01 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
Hi Hiber,

I just skimmed the tutorial to see what they were doing. I haven't gone through MyEclipses tutorials in detail. I would suggest you ask on the MyEclipse forums about their tutorials ;)

_________________
Max
Don't forget to rate


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 10 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.