Entity class Baseentity.java
Packagecom.rock.cft.hibernate;Importjava.util.Date;ImportJavax.persistence.GeneratedValue;ImportJavax.persistence.GenerationType;Importjavax.persistence.Id;ImportJavax.persistence.MappedSuperclass;//@MappedSuperclass used on top of the parent class. This callout is added when the class is definitely a parent class. If you change to @entity, after inheritance, multiple classes inherit, only one table is generated, not multiple inheritance, and multiple tables are generated@MappedSuperclass Public Abstract classbaseentity {PrivateInteger ID;//Database primary Key PrivateDate CreationTime;//creation Time PrivateDate Modificationtime;//Modification Time@Id @GeneratedValue (Strategy=Generationtype.auto) PublicInteger getId () {returnID;} Public voidsetId (Integer id) { This. ID =ID;} PublicDate GetCreationTime () {returnCreationTime;} Public voidsetcreationtime (Date creationtime) { This. CreationTime =CreationTime;} PublicDate Getmodificationtime () {returnModificationtime;} Public voidsetmodificationtime (Date modificationtime) { This. Modificationtime =Modificationtime;} }
Entity class Test_no1.java
PackageCom.rock.cft.test.model;Importjava.io.Serializable;Importjava.util.Date;ImportJavax.persistence.Column;Importjavax.persistence.Entity;Importjavax.persistence.Table;Importcom.rock.cft.hibernate.BaseEntity; @Entity @table (name= "Test_no2") Public classTest_no1extendsBaseEntityImplementsSerializable {PrivateString name;Private intAge ; PublicString GetName () {returnname;} Public voidsetName (String name) { This. Name =name;} Public intGetage () {returnAge ;} Public voidSetage (intAge ) { This. Age =Age ;} }
Entity class Test_no2.java
PackageCom.rock.cft.test.model;Importjava.io.Serializable;Importjava.util.Date;ImportJavax.persistence.Column;Importjavax.persistence.Entity;Importjavax.persistence.Table;Importcom.rock.cft.hibernate.BaseEntity; @Entity @table (name= "Test_no2") Public classTest_no2extendsBaseEntityImplementsSerializable {PrivateDate Testbri; PrivateString Testadr; PublicDate Gettestbri () {returnTestbri;} Public voidSettestbri (Date testbri) { This. Testbri =Testbri;} PublicString Gettestadr () {returnTestadr;} Public voidSettestadr (String testadr) { This. Testadr =Testadr;} }
This results in the generation of tables only: Test_no1, Test_no2 two tables, and both tables contain ID, CreationTime, modificationtime three properties
But if you change the @mappedsuperclass to @entity, you're going to create a baseentity table.
The use of @MappedSuperclass