database - JPA/Hibernate Difference MappedSuperclass and Entity Abstract Class -
i know difference between mappedsuperclass
, entity abstract class
when 1 wants derive super class in hibernate
. know hibernate
not create table in database mappedsuperclass
. read in javaee
doc "abstract entities concrete entities cannot instantiated". since cannot instantiated, deduce there no matching table in database. right?
if so, virtually difference between using mappedsuperclass
, entity abstract class
, impact on software , in database in each case?
a mappedsuperclass uses inheritance field , code reuse. example, if want entities have long id
, long version
field, make them extend baseentity
class annotated mappedsuperclass
containing these 2 fields, along getters, setters, etc. never have entity having association baseentity: association specific subclass of baseentity.
a parent entity used "entity polymorphism". example, imagine having 2 kinds of message
: emailmessage
, smsmessage
. both contain source, target, , body. emailmessage have email address , subject, whereas smsmessage have phone number.
and imagine having person
entity containing collection of sent messages, of type message
. collection in fact contain instances of emailmessage , of smsmessage. hibernate decide 1 instantiate depending on inheritance strategy used inheritance mapping:
- all messages stored in same table, , hibernate use discriminator column containing type of message
- the emailmessage stored in 1 table, , smsmessage stored in one
- or fields common both entities (source, target, body) stored in comon table, fields specific emailmessage in second table, , fields specific smsmessage in third table.
Comments
Post a Comment