Let's I have table
USER
-id : long
-login : varchar
-weapon: varchar
-magic: varchar
And I want map this Table on two classes (using Hibernate/JPA)
class Mag
{
long id;
String login;
String weapon;
}
and
class Warrior
{
long id;
String login;
String magic;
}
And if I send HQL query : SELECT m FROM Mag m WHERE m.login = ?
then I get Mag instance
and if I send HQL query : SELECT w FROM Warrior w WHERE w.login = ?
then I get Warrior instance
I try make something like this
@Entity
@Table(name = "User")
class User
{
long id;
String login;
}
@Entity
class Mag extends User
{
String magic;
}
@Entity
class Warrior extends User
{
String weapon;
}
But @Inheritance requared discriminator column, but I haven't discriminator.
You're looking for MappedSuperClass, which allows the subclasses to inherit the annotations from the superclass without needing a discriminator.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With