PDA

View Full Version : spring.net + nhibernate integration


greatewei
10-06-2005, 11:26 AM
I used the spring+hibernate , it reduced the many code , the app extremely is also clear.
Now nhibernate has release version 1.0 RC3, so I want to try to use spring.net + nhibernate, consulted the spring.net reference documents, the documents also mentions conformity nhibernate, but the consult code, had not discovered the correlation conformity the example.

I want to know Which version spring.net will integrate nhibernate, version 1.1? and about time plan?

Rick Evans
10-10-2005, 05:11 PM
Hi

Data access and ASP.NET web integration are the focus for the 1.1 release of Spring.NET, planned for release at the start of the new year (~January).

On the data side, ADO.NET and iBatis.NET will definitely be supported. So far, no one has expressed an interest in doing any integration with NHibernate... you could always create a JIRA issue (http://opensource2.atlassian.com/projects/spring/secure/BrowseProject.jspa?id=10020) and garner some votes for Spring.NET offering integration with NHibernate if you'd like.

Ciao
Rick

ivolved
11-14-2005, 09:15 PM
Hi

Data access and ASP.NET web integration are the focus for the 1.1 release of Spring.NET, planned for release at the start of the new year (~January).

On the data side, ADO.NET and iBatis.NET will definitely be supported. So far, no one has expressed an interest in doing any integration with NHibernate... you could always create a JIRA issue (http://opensource2.atlassian.com/projects/spring/secure/BrowseProject.jspa?id=10020) and garner some votes for Spring.NET offering integration with NHibernate if you'd like.

Ciao
Rick

Rick,
I've seen a few requests for nHibernate integration in Spring.net and I think it would be wise to have that support in Spring.net because a person coming from Spring Java would probably be very comfortable with the idea of using that combination. (IE it would ease the transistion).
I was JUST introduced to Java Spring (although I had heard and read about it for a while) on my most recent project. Although I don't think that Spring.net should be an EXACT port of Java Spring, I think it would be great if someone could port their skills in Java Spring/Hibernate over to Spring.net/nHibernate with nominal effort.
With that in mind, if no one else has taken the reigns for Spring.net-nHibernate integration, I would like to take on the task, seeing that I will be needing it myself. I'll start it as a contrib project on my own server and if the team deems me worthy, will make it part of Spring.net proper. Development starts, this evening for me.

Michael

Mark Pollack
11-14-2005, 09:34 PM
Hi Michael,

Glad to hear it! I had an email a while ago from someone who was critical of the Spring.Java approach to hibernate integration in the context of how it translated to .NET. I'll forward it to you, the conversation with that fellow has died off unfortunately.

Cheers,
Mark

Rick Evans
11-15-2005, 09:51 AM
Hi

With that in mind, if no one else has taken the reigns for Spring.net-nHibernate integration, I would like to take on the task, seeing that I will be needing it myself. I'll start it as a contrib project on my own server and if the team deems me worthy, will make it part of Spring.net proper. Development starts, this evening for me.

Nice one... its good to see someone picking up the ball and running with it.

One area that you and I (and gee everyone I guess) will probably want to get together on is transation management. I daresay its a little ways down the road, but there is currently little to no transaction management. All of the core interfaces from Spring Java are there (in the Spring.Data project in the sandbox, but there are no implementations of any transaction management interfaces currently in CVS (e.g. NHibernatePlatformTransactionManager, etc).

I noticed as I was playing (and I mean playing in the kiddie sense of the word) with NHibernate on Sunday that they have implemented their own connection factory (read javax.sql.DataSource)... unsurprisingly, the iBatis.NET team also have their own connection factory interface (I forget what its called straight off the top of my head). I was speaking with Erik Doernenburg (http://erik.doernenburg.com/home.html) (of ThoughtWorks (http://www.thoughtworks.com/) and NEO (http://neo.codehaus.org/) fame) a few weeks back (concerning Spring.NET / NEO integration) and we talked about javax.sql.DataSource and what a great interface it is (if everyoe on these disparate projects could agree on an interface for connections it would be good). Being able to control connections (and their attendant transactions) is crucial to a robust and complete transaction management strategy, so now that everyone seems to be straining at the leash to get the Spring.Data stuff done, we can hopefully get some cross project traction here.

Oh yeah, if you are going to start an integration project (and incubate it on your own box), the namespace that was mooted for such integration projects is Spring.Integration.YourTechHere . So in the case of NHibernate, the root namespace would be Spring.Integration.NHibernate... just thought I'd mention it, and yeah, it is still up for discussion :)

Ciao
Rick

Mark Pollack
11-15-2005, 03:17 PM
Hi,

In terms of DataSource like abstractions, I've been playing a bit with making a new AdoTemplate. It seems to me the way to go is along the lines of the DbProviderFactory class in ADO.NET 2.0. See msdn (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnadonet/html/genericdacode.asp) for some sample usage. That said, also I believe we can collapse the Spring.Java StoredProcedure, SqlUpdate, etc classes into AdoTempate. This is primarily because the ado.net command approach for dealing with text and stored procs is better than what you have to do in jdbc. It also means that in some cases if we would call something like "addParameter" on AdoTemplate we will build state inside that instance of AdoTemplate, i.e. "prototype" usage. Now the only state in JdbcTemplate is the connection, it is probably typically used as a singleton, and everything is passed in as method parameters. Squeezing in all thost method parameters in the case of parameters is frankly quite ugly in JdbcTemplate. Hope to have something to show soon....

Cheers,
Mark

equiv
11-24-2005, 04:00 PM
Michael,

I've been using nhibernate recently and I'll need to start working with Spring.net soon. I want to help you with the spring-nhibernate integration.

Esteban

Dimon
03-29-2006, 08:45 AM
Hi guys! I already use Spring and NHibernate in my projects last half year and I'm agree that it would be very usefull and helpfull to have NHibernate implementation in Spring.ADO module :)

Mark Pollack
03-29-2006, 01:53 PM
Hi,

Have you guys tried the spring-nhibernate integration that is currently in the sandbox? There are only a few things missing as compared to the Spring.Java version
1) generate proxy for ISession to suppress calls to close.
2) asp.net module to store session in callcontext for lifecycle of page processing.
3) exception rollback rules - right now rollback on any exception thrown.
4) setting of isolation level property
6) integration with AdoTemplate (use tx/connection as started from ado.net and vice-versa)

The daily builds include the spring.nhibernate dll and the api is very straightforward. The integration test code shows sample usage and a little bit is described here (http://forum.springframework.net/viewtopic.php?t=403) - Let me know and I'll be happy to help bootstrap you using it.

Cheers,
Mark

Dimon
04-01-2006, 09:40 PM
Hi Mark!

I have just tried the NHibernate integration with Spring and it is real cool! Thank you and all team. Well, I'm waiting very much when you finish these few things you describe above and hope it will be soon :wink:

Most wanted for me and many of our developers is asp.net module to store session in callcontext for lifecycle of page processing. We are going to start new project and I would like to know have you got some approximate forecast for these features?

Thanks in advance! You made great work! :lol:

Mark Pollack
04-02-2006, 07:04 PM
Hi,

Thanks for the support! The start of an OpenViewInSession module for asp.net can be found here (http://forum.springframework.net/viewtopic.php?t=414). I will be looking into that myself in the coming weeks but will be focusing on the 1.0.2 releast for April 10th and 1.1 Preview Release on May 1st. I'll ping back here once I move the NHibernate support into a seperate 'integration' project and out of the sandbox.

Cheers,
Mark

bway
04-13-2006, 06:27 PM
Hello Mark, et. al.

I have recent begun evaluating spring.net the the nhibernate integration for a project I am working on. I'm an expert on either at the moment so forgive any noobie-itus.

I have built and run the nhibernate integration test from the sandbox and I must say it is very cool. Nice work!

I would like to take the integration one step further and integrate Spring AOP with the entity level objects constructed by nhibernate. I have seen other references to this such as the "AOP without ProxyFactory" thread in the AOP forum, http://forum.springframework.net/viewtopic.php?t=303 but it doesn't appear to have been completed yet.

I'm soliciting advice on how this might best be accomplished. At the moment I was considering adding ProxyFactoryObjects to the Nhibernate callbacks in the HibernateTemplate. This appears to be the place that all that work is consolidated. I don't understand all the details yet, but I was presuming that I could:

1. define a ProxyFactoryObject in the XML file
2. retrieve the proxy from the XmlApplicationContext
3. set the target property to the object returned from nhibernate
4. return proxy.getObject()

Am I close?

I'm assuming I'll have to go through the returned collections and wrapper each of those objects individually. Probably removing them and stuffing the proxy back into the collection.

I'll probably also have to unwrapper them in the save callbacks as well.

Any other words of wisdom?

Thanks,
Bob Way

Mark Pollack
04-14-2006, 07:17 PM
Hi,

You can use ProxyFactory directly to add AOP advice to your domain object - that works just fine. The simple example from the AOP Quickstart (http://www.springframework.net/doc/reference/html/aop-quickstart.html) shows this in action,


ProxyFactory factory = new ProxyFactory(new ServiceCommand());
factory.AddAdvice(new ConsoleLoggingAroundAdvice());
ICommand command = (ICommand) factory.GetProxy();


As far as I can tell there isn't a need to declare anything proxy releated in the spring config file for you needs.

The current limitation in this approach is that you can only proxy methods that are defined on an interface. So at this point your domain object would need to implement an interface and only those methods can have advice applied to them. To overcome this limitation we are planning to support an inheritance based proxy implementation - you would still need to indicate the domain object's methods as being virtual - they are not virtual by default. This would also give better performance. The current implementation is more suited towards applying aop to service layer objects. Nevertheless, it does work on domain object - I've created advice that implements all the necessary bits for an object to be properly editable inside a data grid.

The two places you could do this for loading data would be in Spring's hibernate callback or use NHibernate's interceptor. I have not tried to save again one of these proxied objects, there maybe issues. I'd appreciate feedback if you try it out.

Cheers,
Mark

swalters
05-19-2006, 10:09 PM
Have you guys tried the spring-nhibernate integration that is currently in the sandbox? There are only a few things missing as compared to the Spring.Java version
1) generate proxy for ISession to suppress calls to close.
2) asp.net module to store session in callcontext for lifecycle of page processing.
3) exception rollback rules - right now rollback on any exception thrown.
4) setting of isolation level property
6) integration with AdoTemplate (use tx/connection as started from ado.net and vice-versa)

The daily builds include the spring.nhibernate dll and the api is very straightforward. The integration test code shows sample usage and a little bit is described here - Let me know and I'll be happy to help bootstrap you using it.

Cheers,
Mark



Hi Mark,

The sandbox code works great for me, but I want to use a service layer to make several DAO calls within one transaction and every call to my dao is starting/committing a transaction. I'm using the TransactionInterceptor to control the transactions and I think I've got everything set-up correctly.

Is Item #1 from above the reason the session keeps opening/closing for each call to HibernateTemplate?

If so, are there any plans to implement the items above in the near future?

Thanks,

-Shane

Mark Pollack
05-19-2006, 10:21 PM
Hi Shane,

Glad the code is working out for you. I didn't remember observing the behavior you are reporting in my tests but I'll look into it. Check out the TemplateTests example to see if anything was misconfigured. You certainly should be able to span the tx across multiple DAO calls - that is a key feature!

In anycase, I plan to implement point #1 this weekend. I have just moved the NHibernate code under the top level cvs module "Spring.Net.Integration". This will let us make releases at a more frequent schedule. Within the next 2 weeks there should be an early access version, with docs, examples, etc, for you to download as well as nightlies.

I'll post back here once the changes are in. Thanks for being an early adopter!

Cheers,
Mark

Mark Pollack
05-20-2006, 09:21 PM
Hi Shane,

I believe there must be something incorrect in your configuration. I've put up example code for this scenario on the wiki forum area (http://opensource.atlassian.com/confluence/spring/display/NET/Forum+Questions). You can also find the code in CVS under the module Spring.Net.Integration. Let me know how it turns out.

Cheers,
Mark

swalters
05-22-2006, 02:19 PM
Hi Mark,

The light bulb finally came on after working through your example vs my code. I was using the concrete Service manager in the test code instead of the ProxyFactoryObject implementation. I guess I don't understand the AOP proxying as well as I thought.

Thanks for the quick response and test case. I'm looking forward to using the Nhibernate and ADO support in the near future.

-Shane