I have two objects with same fields, but from different tables (foo_something and bar_something in fact not plain tables, there are results of several join operations). I use @Subselect hibernate annotation for fetching data. Can I make class structure like this, but which working fine? This class structure doesn't work because annotations doesn't inherit. If I use @Inheritance annotation, I get error Unknown column foo_somethingca0.DTYPE
class Something {
@Id @Column Long id;
@Column String name;
@Column String description;
//getters, setters, constructors
}
@Entity
@Immutable
@Subselect("SELECT id, name, description FROM foo_something")
class FooSomething extends Something {
}
@Entity
@Immutable
@Subselect("SELECT id, name, description FROM bar_something")
class BarSomething extends Something {
}
UPD.
Thanks, @HenryMartens, I added annotations @Entity and @Inheritance with TABLE_PER_CLASS strategy, and made class abstract, now it's working fine:
@Entity
@Inheritance(strategy = TABLE_PER_CLASS)
abstract class Something {
@Id @Column Long id;
@Column String name;
@Column String description;
//getters, setters, constructors
}
@Entity
@Immutable
@Subselect("SELECT id, name, description FROM foo_something")
class FooSomething extends Something {
}
@Entity
@Immutable
@Subselect("SELECT id, name, description FROM bar_something")
class BarSomething extends Something {
}