@MappedSuperclass的用法
来源:互联网 发布:windows xp纯净版 编辑:程序博客网 时间:2024/05/08 17:08
实体类baseEntity.java
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.java
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.java
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的表
0 0
- @MappedSuperclass的用法
- @MappedSuperclass的用法
- @MappedSuperclass的用法
- @MappedSuperclass的用法
- @MappedSuperclass的用法
- @MappedSuperclass的用法
- @MappedSuperclass的用法
- @MappedSuperclass的用法
- @MappedSuperclass的用法
- @MappedSuperclass的用法
- @MappedSuperclass的用法
- @MappedSuperclass的用法
- @MappedSuperclass的用法
- @MappedSuperclass 用法
- @MappedSuperclass注解的使用说明
- @MappedSuperclass注解的使用说明
- @MappedSuperclass
- @MappedSuperclass
- HDU 2044
- 在jsp页面生成二维码
- cocos2d-x网络编程 连接php服务器笔记2
- Android数据库高手秘籍(八)——使用LitePal的聚合函数
- 【数据结构】用C++实现双循环链表的各种操作(包括头删,尾删,插入,逆序,摧毁,清空等等)
- @MappedSuperclass的用法
- iOS开发中NSRunloop跟NSTimer的问题
- Composite(组合)模式
- laravel 学习笔记——路由(中间件与路由组)
- 浏览器无法访问网页解决
- objective-c runtime安全措施之二:反注入
- HDU 2046
- 学无止境——五月总结
- 输入阻抗&输出阻抗