-->
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.  [ 2 posts ] 
Author Message
 Post subject: Inheritance issue !
PostPosted: Wed Jan 05, 2005 11:08 am 
Newbie

Joined: Wed Jan 05, 2005 10:36 am
Posts: 1
Location: Bangalore, India
[b]Hibernate version:2.1.6[/b]

I am facing a strange situation!

The scenario is this:

My application has the following class hierarchy:
[b]
Class A is the base class (and is concrete!)
Class B extends A
Class C extends B
[/b]

The hibernate-mappings file has mapping for all the 3 classes. The mapping does not have any indication of the inheritance hierarchy (copied all required properties for each class and no "sub-class" tag was used).

Now I am using the following sequence to populate Class A with data from the a table in database.
[b]
A a = new A();
a.setId("abc");
Session s = factory.openSession();
[i]Criteria cri = s.createCriteria(a.getClass());[/i]
criteria.setFirstResult(0);
criteria.setMaxResults(10);
cri.list();
[/b]

The intent is to get an instance of class A with data corresponding to the id.

What i get is objects of type C which is a subclass of A and not of A which I require?? How do i get instances of A and not C ? I thought [i]Criteria cri = s.createCriteria(a.getClass());[/i] would be an indication to HIbernate to create instances of A!!

Can somebody help?

Thanks.
Utkarsh


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 05, 2005 11:33 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Fill out the form in the text area, we don't know what you do.


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