JSF - Spring and Hibernate

Hi All,

Currently i have a project on JSF. I need to port this to a Spring and Hibernate framework. I use Eclipse 3.2 and Jboss 4.0.2 and MSSQL. Now i need some really simple tutorials to understand Hibernate and Spring frameworks. Also is it possible to have JSF and Spring work together? Can i get sample tutorials somewhere on JSF and Hibernate?

thanks,

Dilip

[387 byte] By [dilip_jsfa] at [2007-11-27 7:10:20]
# 1

Yes, it is possible for Hibernate, Spring and JSF to work together.

Since Hibernate is persistence technology, it is orthogonal to JSF. In othe words, they handle different concerns and will not interfere with each other.

Spring and JSF however have some overlap. First, Spring has a web component that you will simply not use. Second, both JSF and Spring provide injection containers -- you can give the JSF container access to the Spring container by using one of the VariableResolver implementations provided by Spring.

Go to the Spring web site, http://www.springframework.org, for more information. They have a lot of documentation and a forum as well.

RaymondDeCampoa at 2007-7-12 19:01:49 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2

Raymonds respopnse is excellent. I would just add/ask the relationship between Hibernate and Spring. I have issues with Spring not with is it good or bad but in that it overlaps lots of J2EE technologies and can be confusing when you say integrate.

To integrate core spring into JSF all you need is a variable resolver and this is straight forward and can be found in Spring framework. Hibernate can also be integrated into Spring framework persistance and/or used directly by JSFas JPA. You will have to determine which direction is appropriate for you.

smurray_eriea at 2007-7-12 19:01:49 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3

Thanks for the excellent response but which is the best way to start off , reading the documentation or implementing an example? The documentation for Spring is quite big and i dont seem to understand the concepts of Inversion Control and Injection etc.

I have only worked with JSF. That was kinda easy as there was this faces-config.xml, few jars, use the jsf tags, write a bean and run the sample app.

Can i find something on these lines for Spring? I have very little idea about other familiar frameworks like Struts etc.

dilip_jsfa at 2007-7-12 19:01:49 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 4

As far as documentation vs examples, that depends on the individual.

The Spring documentation is quite large, but Spring itself is very modular. So you can pretty much get away with reading the pieces you need when you need them and ignoring the rest.

Start with inversion of control until you feel you understand the concept. At its core, the idea is simple. Suppose you have a business class, FooService, and it needs to utilize BarService to implement its business logic. The non-Spring way would be to have the FooService class be responsible for getting an instance of BarService. The Spring way is for FooService to have a setter to be given an instance of BarService:

public class FooServiceImpl implements FooService

{

private BarService barService;

public void setBarService(BarService barService) { this.barService = barService; }

}

Then the Spring container is used to "wire together" the instances:

<beans>

<bean id="barService" class="BarServiceImpl" />

<bean id="fooService" class="FooServiceImpl">

<property name="barService" ref="barService" />

</bean>

</beans>

Note the advantage when using the classes in different contexts, e.g. unit testing vs production.

If I were you, I would take the sample app you have already done with JSF and try to integrate Spring into it. Move all the business logic into beans in the Spring container while keeping the view logic in the JSF layer.

RaymondDeCampoa at 2007-7-12 19:01:49 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...