The use of @MappedSuperclass

Source: Internet
Author: User

Entity class Baseentity.java

Package com. Rock. CFT. Hibernate;

Import java. Util. Date;

Import javax. Persistence. Generatedvalue;
Import javax. Persistence. GenerationType;
Import javax. Persistence. Id;
Import javax. Persistence. Mappedsuperclass;

//@MappedSuperclassUsed 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 Class BaseEntity {
Private IntegerId;Database primary Key
Private DateCreationTime;Creation time
Private DateModificationtime;Modification time

@Id
@GeneratedValue(Strategy= GenerationType.AUTO)
Public IntegerGetId() {
ReturnId;
}
Public voidSetId(IntegerId) {
This.Id=Id;
}
Public DateGetCreationTime() {
ReturnCreationTime;
}
Public voidSetcreationtime(DateCreationTime) {
This.CreationTime=CreationTime;
}
public date Getmodificationtime () {
   Modificationtime  }
 public void (date Modificationtime {
  . Modificationtime = Modificationtime  }


}

Entity class Test_no1.java

Package com. Rock. CFT. Test. Model;

import Java.. Serializable import Java.. Date

import Javax.. Column import Javax.. Entity import Javax.. Table

Import com. Rock. CFT. Hibernate. BaseEntity;

@Entity
@Table (name= "Test_no2" )
public class test_ No1 extends baseentityimplements serializable{
 

 private string Name  private int age< Span class= "pun",

Public StringGetName() {
ReturnName;
}
Public voidSetName(StringName) {
This.Name=Name;
}
 public int () {
   return Age &NBSP;}
 public void (int Age) {
  this.= Age &NBSP;}
&NBSP;&NBSP;

}


Entity class Test_no2.java

Package com. Rock. CFT. Test. Model;

Import java. Io. Serializable;
Import java. Util. Date;

import Javax.. Column import Javax.. Entity import Javax.. Table

Import com. Rock. CFT. Hibernate. BaseEntity;

@Entity
@Table(Name="Test_no2")
Public Class Test_no2 Extends BaseEntity Implements Serializable {


Private DateTestbri;

Private StringTestadr;

Public DateGettestbri() {
ReturnTestbri;
}
Public voidSettestbri(DateTestbri) {
This.Testbri=Testbri;
}
Public string Gettestadr () Span class= "pun" >{
  return Testadr &NBSP;}
 publicvoid Settestadr (string Testadr) {
   this. Testadr = Testadr &NBSP;}
&NBSP;
&NBSP;



}

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.