Spring meets Hibernate: a design question

Hi, I'm playing around with Spring and Hibernate but I don't know exactly how to integrate them.What I have is:

One java project with Hibernate. It has 1 classes (say User.java ). and the respectively hbm.xml files and all the Hibernate framework installed and running good. I also have another project, a web project with the Spring framework integrated and also working good.

Now suppose I have this web page where the user enters a username and pwd. Then it goes to the validator and then to the controller class. My question is: what's the best way, in terms of design strategy, to pass the information to the Hibernate project in order to validate in the db and pass the result back to the controller?

thanks in advance,

Manuel Leiria

[773 byte] By [manuel.leiriaa] at [2007-11-26 15:24:56]
# 1

I created a AuthenticateService.java in the Hibernate project wich looks like this:

public class AuthenticateService{

public boolean authenticateUser(String username, String password){

Session session = HibernateUtil.getSessionFactory().getCurrentSession();

//query the db

session.getTransaction().commit();

return theResult;

}

}

and this class is called in my controller and is registred in my projectName-services.xml i.e.,

<beans>

<bean id="authenticateService" class="org.projectName.AuthenticateService">

</bean>

</beans>

Now the problem is that when I start the application, the spring framework gives me an error because it tries to register the bean org/hibernate/Session and gives me a NoClassDefFoundError.

If I include the hibernate jars in my web project I don't have this problem but this jars are already included in the hibernate project wich is referenced in the web project (I'll have hibernate jars in two different places) and I don't think this is correct!

thanks in advance,

Manuel Leiria

Message was edited by:

manuel.leiria

manuel.leiriaa at 2007-7-8 21:40:31 > top of Java-index,Java Essentials,Java Programming...
# 2
If you're already using Spring, why aren't you using the Hibernate support that's built in?%
duffymoa at 2007-7-8 21:40:31 > top of Java-index,Java Essentials,Java Programming...
# 3
spring gives you hibernate support out of the box
georgemca at 2007-7-8 21:40:31 > top of Java-index,Java Essentials,Java Programming...
# 4
Great minds thinking alike, George.%
duffymoa at 2007-7-8 21:40:31 > top of Java-index,Java Essentials,Java Programming...
# 5
> Great minds thinking alike, George.> > %or fools, differing seldomly? :-)
georgemca at 2007-7-8 21:40:31 > top of Java-index,Java Essentials,Java Programming...
# 6
yes, I know that but I'm trying to have two separated projects
manuel.leiriaa at 2007-7-8 21:40:31 > top of Java-index,Java Essentials,Java Programming...
# 7
You might consider using the EJB-3 facade for Hibernate (you need to be on Java 1.5). That gives you an industry standard persistence interface, which will give you more flexibility.There's Spring support for it, but it doesn't need a whole lot.
malcolmmca at 2007-7-8 21:40:31 > top of Java-index,Java Essentials,Java Programming...
# 8

> You might consider using the EJB-3 facade for

> Hibernate (you need to be on Java 1.5). That gives

> you an industry standard persistence interface, which

> will give you more flexibility.

>

> There's Spring support for it, but it doesn't need a

> whole lot.

Can you please explain it a little further?I'm totally new to Hibernate.

thanks,

Manuel Leiria

manuel.leiriaa at 2007-7-8 21:40:31 > top of Java-index,Java Essentials,Java Programming...