Spring + Hibernate

I just came across the Spring Framework like only yesteryday. And found it to be a blast. W00t! Haha…

However I also do understand that Spring can link up with Hibernate in some ways… the current Framework I linking with my databases… can someone explain to me how?

Cheers!

It’s not linked up as soon as your linking something in spring you go down a path of frustration and pain.

it is placed on top of the framework. the confusing bit that most ppl get lost in that springmvc is counted with the framework it’s not(just part of the distribution.), its also placed on top of the framework.

I use Spring (with Tiles) and Hibernate at work and while it does offer some advantages for big projects, it has a steep learning curve and sometimes complicates simple things.

@cylab: what’s your opinion on Hibernate? I used it because I thought it is really cool the way you can map relational database tables with objects. But then, as you mentioned, there are tons of things that actually seem to make life harder compared to using PreparedStatement.

hibernate is nice profided you use xdoclet(or annotations I suppose) to generate hbm mappings. that and HQL is just great.

So I get you right… If I want to link Spring and Hibernate all I have to do is to configure Spring such that the Hibernate Componets will be covered?

Cheers!

@kingaschi
My opinion changes from day to day even after using hibernate for 2 years now :wink: If everything goes well, hibernate is really great, if you have a bug, you curse the day you started with that mess. :slight_smile: So I don’t know if I like it. There is a nice abstraction for relations and such, but then again I constantly shooting myself in the foot with hibernate sessions, lazy loading, custom types etc. :confused:

@ENC
Yes:


	<!-- This is an example for using hibernate with Annotations in spring -->
	<bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
		<property name="dataSource">
			<ref local="dataSource"/>
		</property>
		<property name="hibernateProperties">
			<props>
				<prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
			</props>
		</property>
		<property name="annotatedClasses">
			<list>
				<value>[yourannotatedclass1]</value>
				<value>[yourannotatedclass2]</value>
				<value>[yourannotatedclassN]</value>
			</list>
		</property>
	</bean>

	<bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
		<property name="jndiName">
			<value>java:/[yourdatasource]<value>
		</property>
	</bean>

	<!-- Now you can use set the sessionFactory as property of your service class and use it to query the database -->
	<bean id="yourservice" class="[yourserviceclass]">
		<property name="sessionFactory">
			<ref local="sessionFactory"/>
		</property>
	</bean>
      

your not using spring’s stuff for transactions then cylab?

http://www.springframework.org/docs/reference/transaction.html

as long as I’m consistent in appling on wenn and how collections should be loaded I’m ok.

I was not in the project I took the example from. Normally we do.

We persist a complete data model of a fairly complex application with a lot of interdependencies and some custom types using hibernate, so we mostly have to use lazy loading and reduce cascades to prevent hibernate from reading the whole database . What makes the situation worse is the use of hibernate enhanced data objects in form beans, so there are some catches, since the hibernate session could already be closed when accessing a lazy loaded property etc. etc.

Hallo Landsmann :wink:

Hallo Landsmann? ???

I’m probebly beeing dense.

Nevermind, just a misconception. It’s a common mistake for a german to write “wenn” instead of “when”, so I thought you must be german.

ne I’m dutch and dyslectic, so yer close. 8)

LOL

http://zaedno.de/gallery/albums/userpics/10010/normal_Holland.jpg

:-* :wink:

Another question… Spring and Hibernate are linked via XML correct? SO in that case

Struts , Spring and Hibernate also can be joint as one application correct? However my friend insist that is not possible cause he has tried. He even bet with me 300 bucks if I can come up with an application which conisist of all three frameworks together…

PS: I don’t feel like losing 300 bucks :-\

Cheers!

http://www-128.ibm.com/developerworks/java/library/j-sr2.html

IoC is configured though xml (most of the time, annotations are possible too)

struts can be plugged into spring as a view component. As I pointed out in my other msg in this thread try linking it and it will get messy, he probebly tried to start the spring container from struts. Which will work but leads to all kinds of issues.

http://64.233.183.104/search?q=cache:Q56Fv_ntmNAJ:www.springframework.org/node/267+spring+"6.+Birthdate+-+demonstrates+Struts+integration."&hl=en&ct=clnk&cd=1
also see the attachment I extracted the example from the release. (rename to birthdate.rar)

has anyone fiddled with JSR 170 and jackrabbit? I just came across it I found that the ppl at spring where already working on it http://forum.springframework.org/showthread.php?t=17763&page=3

I renamed it… but cannot be open?

yeah it seems to be corrupted java-gaming.org seems quite unstable from here.

http://prdownloads.sourceforge.net/springframework/spring-webflow-1.0-rc4.zip

I though it was in there.

It seems that the classes which they use here are not from the original springframework is there any examples that uses from the default springframework… (Classes which are specified in SpringFramework 2.0)

By the way… I already lost my 300 bucks… so sad.