-->
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.  [ 6 posts ] 
Author Message
 Post subject: How to read from a view and update a table ?
PostPosted: Thu May 11, 2006 5:51 am 
Newbie

Joined: Thu May 11, 2006 5:43 am
Posts: 3
I have the following situation :
I want to map a class to a view, but to insert rows into a table.
The view is a union of 2 tables with the same structure, but different primary keys, so a can't use the view to update one of the tables.
Any suggestion would be appreciated.
Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 11, 2006 6:28 am 
Senior
Senior

Joined: Thu Aug 25, 2005 3:35 am
Posts: 160
I've done exactly that.

My solution is to name the view always: tableVIEW (so append the word view to the table name where you would like to insert/update/delete).
Then to create your own persister, which just delegates all the calls for save/update/delete to it's base class, but removes the word 'view'.

works like a charm, but it's not the most beautifull code perhaps.
If there are other insights, i'd love to hear them myself


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 11, 2006 7:32 am 
Newbie

Joined: Thu May 11, 2006 5:43 am
Posts: 3
I have found a lot of references about customer persister on this forum, but no example.
Could you post an example of your persister ?


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 11, 2006 10:30 am 
Beginner
Beginner

Joined: Tue May 17, 2005 7:25 pm
Posts: 43
Location: Somewhere, USA
If you are using SQL Server 2000 or higher, you can use a feature called INSTEAD OF TRIGGERS. These triggers allow to define the update/insert/delete behavior for a view that would otherwise be read-only. That way, you just have to map the view as you would if it were a table.


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 11, 2006 10:52 am 
Newbie

Joined: Thu May 11, 2006 5:43 am
Posts: 3
smudges wrote:
If you are using SQL Server 2000 or higher, you can use a feature called INSTEAD OF TRIGGERS. These triggers allow to define the update/insert/delete behavior for a view that would otherwise be read-only. That way, you just have to map the view as you would if it were a table.


Thanks for your reply, but I want the application to be portable to another DB, so I rather not use MSSQL features.
An example of custom persister would be great.


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 11, 2006 11:46 am 
Senior
Senior

Joined: Thu Aug 25, 2005 3:35 am
Posts: 160
I can't. I developed it for a customer.
But it's really a class of about 20 lines only...

Check the nhibernate source for examples on how to create your own persistor.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 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.