-->
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.  [ 5 posts ] 
Author Message
 Post subject: NHibernate.Engine.Key question
PostPosted: Thu May 26, 2005 1:56 pm 
Newbie

Joined: Thu May 26, 2005 1:51 pm
Posts: 4
Hi everyone.

I'm still testing NHibernate 0.6.0.0 and I want to know if there is a special reason to construct a unique identifier for an entity class instance with the form {id, tableName} instead of {id, className}.

NHibernate.Engine.Key[line 31] it has a constructor that it receives a IClassPersister parameter that it could do this:

public Key( object id, IClassPersister p ) : this( id, p.ClassName )

Instead of this:

public Key( object id, IClassPersister p ) : this( id, p.IdentifierSpace )

Please, let me know if I'm wrong in my concept.

Thanks,
GS


Top
 Profile  
 
 Post subject: NHibernate.Engine.Key question
PostPosted: Thu May 26, 2005 1:58 pm 
Newbie

Joined: Thu May 26, 2005 1:51 pm
Posts: 4
Ok, I did the change and tested it. It's seems to work fine.

If I want two classes mapped to same table it is the only way (I think).
Please, let me know if there is a special design reason that invalidates this modification.

GS


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 26, 2005 2:09 pm 
Contributor
Contributor

Joined: Thu May 12, 2005 12:59 pm
Posts: 20
You can have two classes mapped to the same table - see http://www.hibernate.org/41.html for a good example why.

You'll probably run into problems with your way once you start dealing with subclasses. Say I've got a base class Fruit and a subclass Apple.

If I execute
Code:
Apple a = session.Load( typeof(Apple), 1 ) as Apple;


and then execute

Code:
Fruit f = session.Load( typeof(Fruit), 1 ) as Fruit;


you'd want f and a to be the same object in memory (assuming session is the same ISession instance). With your modification you'd have two different objects in memory (I believe).


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 26, 2005 4:23 pm 
Newbie

Joined: Thu May 26, 2005 1:51 pm
Posts: 4
Mike,

The example in http://www.hibernate.org/41.html is clear and I had already seen it. Unfortunately my objects hierarchy complexity and design doesn't allow me to have "lightweight" superclass and "heavyweight" class.

Assuming the session is the same, I would want:
    Object A and object B to be different instances in memory.
    To be able to cache object A and object B separately even though they are instantiated through values from the same table.


Please, give me a hand with this problem.
I want to know -if the modification of the Nhib code I did is invalid-
Which would be a suitable way to solve it?

Thanks,
GS


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 27, 2005 11:34 am 
Contributor
Contributor

Joined: Thu May 12, 2005 12:59 pm
Posts: 20
Regardless of lightweight or heavyweight pattern, the example shows how to map two classes to one table. Which is what you are describing.

You're modification sounds okay - the previous posting is where I think the problem will be, and won't be integrated into the nhibernate core. However, it's open source - so feel free to modify your local copy and recompile :)


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