|
From: Rod J. <rod...@in...> - 2004-02-15 10:55:31
|
There are 2 ways you can do this I can think of: 1. Configure Hibernate using the Spring LocalSessionFactory. This means that you end up configuring Hibernate using a DataSource. You can get connections from that DataSource in your JDBC code also, rather than from Hibernate (although they still come from the same pool). This makes Hibernate configuration easier. This is definitely how I'd do it, and works well. 2. Get a connection from Hibernate and create a Spring SingleConnectionDataSource from it to pass to Spring JDBC. This will work, but is really a hack. Spring JDBC is designed to take away the pain of obtaining and closing a connection, among other things. Hence it would deliver less value if it worked with Connections, rather than DataSources. Also, with a DataSource it makes more sense to incur the cost of getting metadata to enabling exception mapping. You wouldn't want to do this for every connection. P.S. We are thinking about searchable resources. However, this won't happen in the near future. ----- Original Message ----- From: "Ezra Epstein" <eep...@pr...> To: <spr...@li...> Sent: Sunday, February 15, 2004 3:05 AM Subject: [Springframework-developer] Hibernate and JDBC connection vs. Spring's need for a DataSource. > First off, I tried searching the existing list, but since it's sourceforge, > search doesn't work. I tried: "hibernate", "datasource", etc. No luck. > Even tried "IHibernateTemplate" which is saw in to topic of one post and > that returned an empty set as well. Sigh. Wouldn't a searchable phpBB > forum be nice... > > Meanwhile, the issue at hand. I'm using Hibernate. I've read about Spring. > I'm thinking Spring sounds great. Want to move to include it. This being a > needs-driven development effort, we have a problem with Hibernate: it has > zero support for stored procedures. So, enter Spring. Nice support for > arbitrary JDBC/SQL. Just write the result-set row handler and you are done. > Sounds perfect. 3 hours later I've abandoned Spring. Why? Well, Spring > wants everything to include a DataSource. But we run Hibernate in 2 modes: > stand-alone, for testing and inside a container for web deployed apps. > Currently we configure Hibernate directly -- easy, external > hibernate.cfg.xml file. But Hibernate's "abstraction" is all based on a > java.sql.Connection object, which for sending queries, makes perfect sense. > So, for the life of me, I can't figure out why Spring always wants a > DataSource and rather than change everything that currently works and move > it all over so that Spring handles configuration and gives itself a > DataSource, I've decided it's not worth it. By then I could have written > the calls and handlers in plain JDBC 3 times over.... Again, this is a > needs-driven effort. > > 2 questions: > > 1. Is there a different entry point to all of Springs JDBC utility methods > that relies on a lowly connection object instead of a DataSource? > 2. If not, why not? > > Thanks, > > == Ee > > > > ------------------------------------------------------- > SF.Net is sponsored by: Speed Start Your Linux Apps Now. > Build and deploy apps & Web services for Linux with > a free DVD software kit from IBM. Click Now! > http://ads.osdn.com/?ad_id=1356&alloc_id=3438&op=click > _______________________________________________ > Springframework-developer mailing list > Spr...@li... > https://lists.sourceforge.net/lists/listinfo/springframework-developer > |