-->
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: Wrong SQL generation on replicating a inherited class.
PostPosted: Wed Mar 14, 2007 2:05 pm 
Beginner
Beginner

Joined: Fri Oct 20, 2006 8:02 am
Posts: 36
The error "could not retrieve version" and the inner error "column unknown" thorws when I try to replicate a C2 object:
C2 c2obj previously instantiated in another database.
Session.Replicate(c2obj,ReplicationMode.Overrite);

My classes:
Code:
class C1
{
   int _id;
   public int Id
   {
      get { return _id; }
      set { _id=value; }
   }
   private string _prop1;
   public string Prop1
   {
      get { return this._prop1; }
      set { this._prop1=value; }
   }
}
class C2 : C1
{
   private string _prop2;
   public string Prop2
   {
      get { return this._prop2; }
      set { this._prop2=value; }
   }
}


Hibernate version:1.0.4

Mapping documents:
Mapping of class C1:
Code:
<?xml version='1.0' encoding='utf-8' ?>
<hibernate-mapping xmlns='urn:nhibernate-mapping-2.0' default-access='field' >
   <class name='C1' table='TBL_C1'>
      <id name='_id' column='id_c1' type='Int32' unsaved-value='0'>
         <generator class='native'>
            <param name='sequence'>seq_id_c1</param>
         </generator>
      </id>
      <property name='_prop1' column='prop1' type='String' length='40' />
   </class>
</hibernate-mapping>

Mapping of class C2:
Code:
<?xml version='1.0' encoding='utf-8' ?>
<hibernate-mapping xmlns='urn:nhibernate-mapping-2.0' default-access='field' >
   <joined-subclass name='C2' extends='C1' table='TBL_C2' >
      <key column='id_c2' />
      <property name='_prop2 column='prop2' type='String' length='35' />
   </joined-subclass>
</hibernate-mapping>


Code between sessionFactory.openSession() and session.close():

Full stack trace of any exception that occurs:

Name and version of the database you are using:

The generated SQL (show_sql=true):
NHibernate.SQL: SELECT id_c2 FROM TBL_C1 WHERE id_c2 = @p0
NHibernate.SQL: @p0 = '1'

the NHibernate generates the sql using the table from the parent class C1 and it should be from the real class C2.


Debug level Hibernate log excerpt:

Problems with Session and transaction handling?

Read this: http://hibernate.org/42.html


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 16, 2007 12:54 pm 
Beginner
Beginner

Joined: Fri Oct 20, 2006 8:02 am
Posts: 36
BUMP


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 16, 2007 2:07 pm 
Expert
Expert

Joined: Fri May 13, 2005 5:56 pm
Posts: 308
Location: Santa Barbara, California, USA
well i was waiting for someone more knowledgable to answer, however, one thing i noticed is that your id column in the C2 table is named differently than the column in the C1 table. when implementing inheritance in the database i always name the PKFK columns the same across all of the inherited tables. so in your case:

Code:
<?xml version='1.0' encoding='utf-8' ?>
<hibernate-mapping xmlns='urn:nhibernate-mapping-2.0' default-access='field' >
   <class name='C1' table='TBL_C1'>
      <id name='_id' column='id_c1' type='Int32' unsaved-value='0'>
         <generator class='native'>
            <param name='sequence'>seq_id_c1</param>
         </generator>
      </id>
      <property name='_prop1' column='prop1' type='String' length='40' />
   </class>
   <joined-subclass name='C2' extends='C1' table='TBL_C2' >
      <key column='id_c1' />
      <property name='_prop2 column='prop2' type='String' length='35' />
   </joined-subclass>
</hibernate-mapping>

and of course, your database tables would have to be updated to reflect this. might be worth a try. NH has to go to the C1 table because C2 might have (inherited) properties that are populated from data in that table (even though, in this case, C1 doesn't appear to inherit any properties from C2.

-d


Top
 Profile  
 
 Post subject: Wrong SQL generation on replicating a inherited class.
PostPosted: Fri Mar 23, 2007 10:23 am 
Beginner
Beginner

Joined: Fri Oct 20, 2006 8:02 am
Posts: 36
Hi devonl;

I just know if I use the same it will work, but It also should work with diferent columns in each table. Because if it only acepts the same column the hbm mapping would not need the <key> element.

It should or not work Sergey?


Top
 Profile  
 
 Post subject: Re: Wrong SQL generation on replicating a inherited class.
PostPosted: Mon Mar 26, 2007 4:55 am 
Newbie

Joined: Mon Jan 29, 2007 2:03 am
Posts: 11
anuarneto wrote:
Mapping of class C2:
<property name='_prop2 column='prop2' type='String'



shouldn't the property be enclosed properly


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 28, 2007 5:39 pm 
Beginner
Beginner

Joined: Fri Oct 20, 2006 8:02 am
Posts: 36
Hi Sergey, should Ii report it on JIRA?


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.