-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 
Author Message
 Post subject: advise on how to use nhibernate with view
PostPosted: Mon Mar 03, 2008 10:24 am 
Beginner
Beginner

Joined: Wed Aug 29, 2007 8:23 am
Posts: 31
Hello.

I was wondering if anyone can help me with a specific scenario. In this case, I have a situation where I have a view that returns all the records of a specific type. this view will get its records from "remote tables" (that is, tables that are stored on a different sql instance) which are joined with a local table.

this local table is used to store users that aren't registered on those "remote tables". So, generally, the user will exist on the remote table (or has already been inserted on the local table) and he will be returned by the view. My problem is knowing if there's any way to configure nhibernate to that it will automatically insert a record on that table.

Resuming, is there any way for me to tell nhibernate that loading the objects should be done by using the view and that inserting them should be done on a table?

thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 05, 2008 8:41 am 
Expert
Expert

Joined: Thu Dec 14, 2006 5:57 am
Posts: 1185
Location: Zurich, Switzerland
You can specify a custom sql statement for loading objects:

http://www.hibernate.org/hib_docs/nhibernate/1.2/reference/en/html/querysql.html#querysql-load

There you can use the view. Insert, update and delete will operate on the local table. You can also use custom sql for these operatons:

http://www.hibernate.org/hib_docs/nhibernate/1.2/reference/en/html/querysql.html#querysql-cud

If you want a create local entry for each loaded remote user, you have to do a little work. Add a property to your class which indicates the origin of the record. After loading check the property and do a session.SaveCopy if the origin is remote or set the "identity" property to "unsaved-value". Then flush the session and you should have the entries in the local table.

_________________
--Wolfgang


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 05, 2008 10:12 am 
Beginner
Beginner

Joined: Wed Aug 29, 2007 8:23 am
Posts: 31
Hello Wolli.

yeah, that might do it! It's just a matter of putting the columns in the correct order and it should work without any problems...thanks!


Top
 Profile  
 
 Post subject:
PostPosted: Sat Mar 22, 2008 5:05 pm 
Contributor
Contributor

Joined: Sun Jun 26, 2005 5:03 am
Posts: 51
Location: London, UK
Another technique I've used quite well on SQL Server, is the use of INSTEAD OF triggers.

You read/write to the view, but the view has a trigger on it to redirect the insert/update to the correct underlying table.

_________________
Paul Hatcher
NHibernate Team


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.