Dmytro Grynets
Dmytro Grynets

Reputation: 953

Hibernate mapping of derived class with no fields

I've encountered situation when I need two classes have same fields, but a slightly different behavior, one of them possess some other field, but another doesn't, so the questions is : do i have to map derived class which have no special fields? Here's example, let's say i have class A, and class B, both have to have some collection(e.g. of C objects) and some other field D, so i create abstract class AB, which is their parent, and while class B also have String field, class A - doesn't, and all of them are descendants of M, which have someMethod():

abstract class M {
    //fields, getters, etc
    public void someMethod(){
    //doSmth
    }
}

abstract class AB extends M {
    private D d;
    private Set<C> cs;
    //getters, setters, etc
}

class A extends AB{
    @Override
    public void someMethod(){
      for(C c : cs){
      //doSmth
      }
    }
}

class B extends AB {
    private String text;
    //getters etc
}

So, I definitely should map M, AB and B, but should i map A?

P.S. we use xml mappings

Upvotes: 0

Views: 196

Answers (1)

Naros
Naros

Reputation: 21113

If you want Hibernate to return you List<A> as a query result, yes you'd need to map A.

Upvotes: 1

Related Questions