I use Hibernate annotation to save my classes. I am currently using the following strategy to map classes
I have an abstract class, which is the parent class, and I have two subclasses that inherit its Mother, father.
I displayed it like this:
@MappedSuperclass public abstract class Parent { private int age; private String name; ... }
And two other classes are declared as follows:
@Entity public Class Father extends Parent { private boolean haveMustash; ... }
Thus, basically the scenario is “Table for each class”.
Now I want to create a Hibernate HQL statement that will update the age of the parent, regardless of its type (mother, father). the parent will be scanned using a name column that is unique in both tables. but I don’t know, just looking at the name if it is Mother or Father. How can I create an HQL statement that will look in both tables and return the correct object for the update?
I thought of something like this: (but I have no idea if this is possible)
Parent parent = hibernateTemplate.find("from Mother,Father where name=" + name);
source share