|
From: <jue...@we...> - 2003-08-19 10:59:17
|
Lars,
Sorry for your frustration - please don't give up :-)
I agree that we should come up with a sample application that uses =
Spring and Hibernate. At this point, I can only say it's in the works, =
as the sample app will also serve for some other purposes. It won't get =
ready before my trip to Australia (the whole of September) though, so we =
will have to wait for October.
Anyway, let's dig into the webapp-hibernate skeleton. Please don't be =
confused by all the options with container resources vs local resources, =
I know that's a rather complex domain (there's even a whole article on =
that in the documentation section the Spring website).
How to set up a Spring/Hibernate application?
1. Define a *JDBC DataSource*. You can take a JNDI one or a local one =
like a Jakarta Commons BasicDataSource. You have chosen a JNDI one =
managed by WebLogic - that's fine.
2. Define a *Hibernate SessionFactory*. Again, you can take a JNDI one =
(only advisable with the Hibernate JCA adapter) or a local one via =
LocalSessionFactoryBean. The latter can get a reference to the =
DataSource from step 1, so that Hibernate accesses that database =
underneath. In your case, choose LocalSessionFactoryBean, as illustrated =
by the webapp-hibernate skeleton. Don't worry about the JNDI option or =
JCA for that matter.
3. Define a *transaction manager*. HibernateTransactionManager or =
JtaTransactionManager are appropriate here. The former needs a reference =
to the Hibernate SessionFactory, as illustrated by the webapp-hibernate =
skeleton. The latter requires the DataSource from step 1 to be a =
transactional container DataSource.
4. Feel free to use any of the above resources in your application =
beans, passed to them via bean references. Internally, your application =
beans can of course use convenience classes like HibernateTemplate and =
TransactionTemplate for resource access.
That's all you need to set up a working Spring/Hibernate application.
You seem to have gotten confused by the option to use a JNDI =
SessionFactory vs a JNDI DataSource. These are two entirely different =
things. As outlined above, you have to choose a respective strategy for =
*either* resource, the JDBC DataSource and the Hivernate SessionFactory.
The comment above the LocalSessionFactoryBean definition in the =
webapp-hibernate skeleton illustrates an alternative for *SessionFactory =
setup*. This has nothing to do with *DataSource setup*, thus it does not =
pose a conflict. I hope I've been able to make that clear.
Finally, thanks for your feedback - there's always room for =
improvement...
Juergen
-----Original Message-----
From: Lars Fischer [mailto:lar...@gm...]
Sent: Tuesday, August 19, 2003 11:52 AM
To: spr...@li...
Subject: [Springframework-developer] Too many options
Hi all,
I'm a little bit frustrated getting started with Spring and Hibernate.
Hibernate works fine now in a non J2EE environment.=20
But I still don't know what to define with Hibernate and Spring (ends=20
up in deployment-descriptor hell).
Has anyone an example with all options (that make sense) when developing
an application with Spring, Hibernate and BEA WebLogic 8.1 ?
The "applicationContext.xml" from the Hibernate skeleton doesn't make
it clear which of the options I should use.
I've defined a connection pool and a data source in WLS and can access =
it
with=20
<bean id=3D"exampleDataSource"
class=3D"com.interface21.jndi.JndiObjectFactoryBean">
<property name=3D"jndiName">
<value>refHibernate</value>
</property>
</bean>
The next option in "applicationContext.xml" is=20
<bean id=3D"exampleSessionFactory"
class=3D"com.interface21.orm.hibernate.LocalSessionFactoryBean">
<property name=3D"mappingResources">
...
There is a comment above stating
" - This definition can be replaced by a JndiObjectFactoryBean =
definition
for fetching
- a JNDI-bound SessionFactory, but this only makes sense when using
Hibernate's
- JCA Connector (not recommended for most types of applications)."
Does this mean that I should only use one of these options ?
These things are all explained in 'high level' documents one can =
understand
if
reading them carefully. But I just want to get started immediately and =
not
spending
hours of reading this kind of abstract stuff.
IMO it's best to stop the Hibernate/Spring testing and use JDBC (where
examples
are provided) until someone provides a real world example with Hibernate
though I think it's like going back=20
a few years when programming with Delphi.
Sometimes it's bad to have too many options. Think of a store where you =
can
buy hundreds
of different products of the same kind. It will take you forever to come =
to
a decision.
Trying with JDBC now ...
Regards
Lars
|