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
|
|