@MappedSuperclass的用法
来源:互联网 发布:qq邮箱的imap端口 编辑:程序博客网 时间:2024/05/16 15:24
实体类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;
//@MappedSuperclass 用在父类上面。当这个类肯定是父类时,加此标注。如果改成@Entity,则继承后,多个类继承,只会生成一个表,而不是多个继承,生成多个表@MappedSuperclasspublic abstract class BaseEntity { private Integer id;// 数据库主键 private Date creationTime;//创建时间 private Date modificationTime;//修改时间 @Id @GeneratedValue(strategy = GenerationType.AUTO) public Integer getId() { return id; } public void setId(Integer id) { this.id = id; } public Date getCreationTime() { return creationTime; } public void setCreationTime(Date creationTime) { this.creationTime = creationTime; } public Date getModificationTime() { return modificationTime; } public void setModificationTime(Date modificationTime) { this.modificationTime = modificationTime; }
}
实体类Test_No1.javapackage com.rock.cft.test.model;
import java.io.Serializable;import java.util.Date;
import javax.persistence.Column;import javax.persistence.Entity;import javax.persistence.Table;
import com.rock.cft.hibernate.BaseEntity;
@Entity@Table(name="test_no2")public class Test_No1 extends BaseEntity implements Serializable { private String name; private int age;
public String getName() { return name; } public void setName(String name) { this.name = name; } public int getAge() { return age; } public void setAge(int age) { this.age = age; }
}
实体类Test_NO2.javapackage com.rock.cft.test.model;
import java.io.Serializable;import java.util.Date;
import javax.persistence.Column;import javax.persistence.Entity;import javax.persistence.Table;
import com.rock.cft.hibernate.BaseEntity;
@Entity@Table(name="test_no2")public class Test_NO2 extends BaseEntity implements Serializable { private Date testBri; private String testAdr; public Date getTestBri() { return testBri; } public void setTestBri(Date testBri) { this.testBri = testBri; } public String getTestAdr() { return testAdr; } public void setTestAdr(String testAdr) { this.testAdr = testAdr; }
}
这样在生成表的时候只生成了:test_no1、test_no2两张表,而且两张表中都含有id、creationTime、modificationTime三个属性但是如果把@MappedSuperclass换成@Entity那么就会另外在生成一张baseEntity的表
- @MappedSuperclass的用法
- @MappedSuperclass的用法
- @MappedSuperclass的用法
- @MappedSuperclass的用法
- @MappedSuperclass的用法
- @MappedSuperclass的用法
- @MappedSuperclass的用法
- @MappedSuperclass的用法
- @MappedSuperclass的用法
- @MappedSuperclass的用法
- @MappedSuperclass的用法
- @MappedSuperclass的用法
- @MappedSuperclass的用法
- @MappedSuperclass 用法
- @MappedSuperclass注解的使用说明
- @MappedSuperclass注解的使用说明
- @MappedSuperclass
- @MappedSuperclass
- Build过程(objc)
- Windows Server 2012 R2 配置SharePoint2013
- setTimeout和setInterval的区别你真的了解吗?
- mysql设置UTF-8字符编码(Ubuntu)
- 关于android输入法的一些记录
- @MappedSuperclass的用法
- C#陈广自学视频笔记2——Array和ArrayList的区别
- 图片加水印
- Sublime Text 3 笔记
- mysql 命令行导入大文件
- 根据手势获取点击的是哪个控件
- 练习---边框式布局
- Cocos2d-x结构学习(五)CCEGLViewProtocol、CCEGLView
- 【c语言】编写一个程序,从标准输入读取几行输入。每行输入都要打印到标准输出上,前面加上行号。在编写这个程序的时候要使这个程序能够处理的输入行的长度没有限制。