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.  [ 3 posts ] 
Author Message
 Post subject: AdHoc Joins
PostPosted: Mon Sep 17, 2007 9:49 pm 
Newbie

Joined: Wed Sep 12, 2007 12:18 pm
Posts: 11
Is there any way to create AdHoc joins between objects based on relationships/associations that aren't formally defined (using things like one-to-one, one-to-many, etc.)?

This is a dumb example and not something I'd do in the real world, but just for arguments sake imagine I have the following classes (incomplete for the sake of brevity):


Code:
  [Class]
  class Contact {
    [Id(Name = "Oid")]
    Guid Oid;
    [Property]
    string FirstName;
    [Property]
    string LastName;
    [Property]
    string StreetAddress;
  }

  [Class]
  class Customer {
    [Id(Name = "Oid")]
    Guid Oid;
    [Property]
    string CustomerFirstName;
    [Property]
    string CustomerLastName;
  }



Can I then do something like the following:

Code:
            IQuery query = session.CreateQuery(
                " SELECT c.Oid "
                + " FROM Customer cst INNER JOIN Contact c "
                + " WHERE cst.CustomerFirstName = c.FirstName "
                + " AND cst.CustomerFirstName = c.FirstName "
                );



Full explanation for my motivations

I'm using nHibernate in an nTier environment and I don't want to load aggregate properties of objects unecessarily. Lazy loading is a concept that doesn't really lend itself to n-tier very well since you only know if you need the property or not once the entity has been read from the databases, sent across the wire and the session already closed...

For example, I wanted all the domain objects that the app is dealing with to have some audit fields (DateTime Created, Guid CreatedById, DateTime LastModified, Guid LastModifiedById)... I simply want to store the Id of the "User" that last modified each object. I don't want to create a strong Many-To-One relationship between every entity in my domain and my User class.

If I did create strong associations between all the objects in the domain and my User class (properties like "User CreatedBy" decorated with the many-to-one attribute) then what I'm scared would happen is the following:
The client application (a windows app) requests the User "Bob" from the application server (a web service running on another machine). The web service, which is using nHibernate to do it's job, then asks nHibernate for the user "Bob" and serializes "Bob" across the wire back to the client app. As the web service has no idea what properties of Bob the client application is interested in, it sends them all back. Now Bob is a User instance that was was last modified by the user Erik. The Erik User class was in turn last modified by Sally which was created by Joe... The result is that the web service streams back the User bob along with umpteen other user class instances which are only tenuously related to Bob via some obscur auditing properties that the client application, as it happens, isn't even interested in for this particular request (which was simply to fetch Bob's details so that it could show them in a "Modify your Profile" dialog box).

Now, elsewhere in the application, I have a grid that presents a read only view of a whole bunch of "Users" and this grid includes columns like the use's logon, domain, their contact details AND when their profile was created, last modified and by whom. In order to create such a grid I need to create a view that joins User entities with other User entities, using the ModifiedById and CreatedById fields (so I can lookup the FileAs field for the users that Created and Modified each profile, using those Id fields)... but I need to do so without creating a strong association between Profiles and other Profiles based on these properties, for the reasons explained above...

Does it sound like my fears above are justified and, if so, is there a way around this so that I can build ad-hoc joins?

TIA

Best Regards,

James Crosswell
Microforge.net LLC
http://www.microforge.net


Top
 Profile  
 
 Post subject: Same problem here...
PostPosted: Wed Feb 18, 2009 1:10 pm 
Newbie

Joined: Wed Feb 18, 2009 11:31 am
Posts: 3
Just posted on this... did you ever figure this out?


Top
 Profile  
 
 Post subject: Same problem here...
PostPosted: Wed Feb 18, 2009 1:14 pm 
Newbie

Joined: Wed Feb 18, 2009 11:31 am
Posts: 3
Just posted on this... did you ever figure this out?


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