Hibernate version:
3.4 using EntityManager
Mapping documents:
N/A
Code between sessionFactory.openSession() and session.close():
N/A, using Seam Managed Persistence
Full stack trace of any exception that occurs:
None
Name and version of the database you are using:
MySQL 5.0
The generated SQL (show_sql=true):
N/A
Debug level Hibernate log excerpt:
N/A
Problems with Session and transaction handling?
No
Code:
@Entity
@Table(name = "pet")
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name = "type", discriminatorType = DiscriminatorType.INTEGER)
public abstract class Pet {
....
}
Code:
@Entity
@DiscriminatorValue("1")
public class Dog extends Pet {
....
}
Code:
@Entity
@DiscriminatorValue("2")
public class Cat extends Pet {
...
}
Code:
@Entity
@Table(name="human")
public class Human {
@ManyToOne(fetch = FetchType.LAZY, optional = false)
@JoinColumn(name = "pet_id", nullable = false)
private Pet pet;
...
}
Code:
Human john = new Human();
john.setPet(new Cat());
Human mary = new Human();
mary.setPet(new Dog());
If I persist john and mary objects and retreive them from the database, Hibernate always returns Pet instances when I call john.getPet() or mary.getPet() and not Dog or Cat instances . What should I do to actually get the Dog/Cat instances? Is that even possible?
Thanks!