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: saving a derived class without descriminator
PostPosted: Mon Apr 06, 2009 11:20 am 
Newbie

Joined: Mon Apr 06, 2009 10:57 am
Posts: 2
Hi all,

i have the following classes:

Code:
public class A
{
    public A(string x)
    {
        // code
    }
    //properties...
}

public class B : A
{
    public B(string x) : base(x)
    {
        // extended code
    }
}


I also have a mapping file for class A.
Now i'm trying to save an instance of B in the A Table.
The only difference to A is the constructor.

I have tried to use a simple explicit cast, but it doesn't work.
NHibernate is still aware that myB is an instance of B an throws a "no mapping file" Exception

Code:
session.save((A)myB);


My biggest problem is that i can't use a descriminator value because i can't touch the database structure.

I only want to save myB in the Table of A, there is no need to load data as an instance of B!

Is there a way to solve this Problem?

Thanks a lot
Roman


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 06, 2009 12:41 pm 
Regular
Regular

Joined: Wed Feb 11, 2009 10:58 am
Posts: 55
Hey :)

You can write an Interceptor for your Session and implement
Code:
public string GetEntityName(object entity)
{
  if(entity is B)
    return "A"; //Use the full name of the class here, including the namespace
  else
    return "";
}


maybe that will work


Top
 Profile  
 
 Post subject: Yippiyeah :)
PostPosted: Thu Apr 16, 2009 8:18 am 
Newbie

Joined: Mon Apr 06, 2009 10:57 am
Posts: 2
Hi,

after updating hibernate to 2.1x it works perfectly!
(see http://nhjira.koah.net/browse/NH-1396 if you have problems with overriding GetEntityName of EmtpyInterceptor)

Thank you very much!

Roman


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.