-->
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.  [ 11 posts ] 
Author Message
 Post subject: Creating an object "view"
PostPosted: Mon Oct 10, 2005 10:34 am 
Contributor
Contributor

Joined: Sat Sep 24, 2005 11:25 am
Posts: 198
I don't know if this is possible, but the idea is that I want to do something like this:
I've an object that doesn't reside in a DB I control, as far as I'm concerned, it's coming from thin air. The object does have a unique Id, and I'm using it all over the database.

I want to create an aggerate object that will holds all the things that relate to this object.
The idea is that then I could treat this object as a surrogate to the real one, and wouldn't have to manage the state of everything myself, I could rely on NHibernate to do it for me.

Is it possible?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 10, 2005 11:47 am 
Contributor
Contributor

Joined: Thu May 12, 2005 9:45 am
Posts: 593
Location: nhibernate.org
I don't understand your problem... Do you mean that you have an heavy entity and you want to create a light version that NHibernate can manage (do CRUD on it)?

You may give an example as illustration :wink:

_________________
Pierre Henri Kuaté.
Get NHibernate in Action Now!


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 10, 2005 11:47 am 
Regular
Regular

Joined: Fri Jun 11, 2004 6:27 am
Posts: 81
Location: Yaroslavl, Russia
Could you explain it in more details? Currently it's not clear what do you want to achieve.

_________________
Best,
Andrew Mayorov // BYTE-force


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 10, 2005 3:18 pm 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
Ayende, if I understand you correctly, a custom persister implementation might be what you need.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 10, 2005 7:20 pm 
Contributor
Contributor

Joined: Sat Sep 24, 2005 11:25 am
Posts: 198
Here is an example:

I've an employee that is an Active Directory user.
In the database I've all sorts of information about that employee, with a column that is the same as the UID.
I want to be able to pull that information via NHibernate into an oject that would aggerate the information about the employee.
The idea is that I would have an EmployeeData object so the object model looks like

Employee - From Active Directory
EmployeeData - Just an aggerator
|_ Salary
|_ Contract
|_ Benefits


The idea is that I would be able to treat the EmployeeData as if it was a NHib object, so if I would set the Salary and flush the session, it would be saved in the Db.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 11, 2005 3:42 am 
Regular
Regular

Joined: Fri Jun 11, 2004 6:27 am
Posts: 81
Location: Yaroslavl, Russia
Then i just don't see a problem here. You have to map your class to NH as usual - map salary, contact and benefits field - and leave all other fields out of NH's competence. In this case it will manage all the data that is stored in the DB, while you will have to make other operations by hands. For example, you will obtain ActiveDirectory user data upon first request.

_________________
Best,
Andrew Mayorov // BYTE-force


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 11, 2005 8:30 am 
Contributor
Contributor

Joined: Sat Sep 24, 2005 11:25 am
Posts: 198
The problem here is that I want to refer to this class from other classes.
For instance, I've a rule about an employee, and that rule is using an <any> element.
How can I do that?
Also, the object doesn't have a table of its own.

The idea is that the database looks like:

Table: Salaries ( EmpId, ... )
Table: Benefits ( EmpId, ... )

How do I tell NHib to use this?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 11, 2005 9:01 am 
Regular
Regular

Joined: Fri Jun 11, 2004 6:27 am
Posts: 81
Location: Yaroslavl, Russia
A-ha, i'm starting to understand: the only trace of employee in the database is its identifier in Salaries, Benefits and other tables, right? Sorry, i didn't understand it earlier. :)

Well, some random thoughts:
1. You can use custom type to obtain an instance of you employee from NH-mapped objects. It's quite simple. For example you can look at Nullables.NHibernate.
2. In your employee class you will have to explicitely query database for its salaries, benefits and so on. It's also not a big problem.
3. As Sergey said, you can create custom persister, but it seems to be not very easy. Perhaps more complex than implementing points 1 and 2.

_________________
Best,
Andrew Mayorov // BYTE-force


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 11, 2005 10:50 pm 
Contributor
Contributor

Joined: Sat Sep 24, 2005 11:25 am
Posts: 198
Thanks for the suggestion, it looks like I'll use the first approach.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Oct 16, 2005 10:09 pm 
Contributor
Contributor

Joined: Sat Sep 24, 2005 11:25 am
Posts: 198
I just took a look on the cusom types in Nullables.NHibernate, it looks like it's just a single column thing.
I don't think that this would do it on its own, I will probably need it for the case where I want to load an employee to a class, but I also need to load the employee class as well.

In other words:

create table salaries(EmpId, ...)

I need the custom type so a Salary would have a referenec to Employee, but I would probably need a custom persister to load the Employee class with all the references to the salaries, etc.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Oct 16, 2005 10:24 pm 
Contributor
Contributor

Joined: Sat Sep 24, 2005 11:25 am
Posts: 198
Are there any samples of using a custom class persisters? The interface looks decidedly non trivial.


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