根据业务建模型时,有一些字段基本每个表都是需要的,如下表:

  1. package com.company.jelly.model;
  2.  
  3. import javax.persistence.EntityListeners;
  4. import javax.persistence.GeneratedValue;
  5. import javax.persistence.GenerationType;
  6. import javax.persistence.Id;
  7. import javax.persistence.MappedSuperclass;
  8. import javax.persistence.Version;
  9.  
  10. import org.springframework.data.annotation.CreatedDate;
  11. import org.springframework.data.annotation.LastModifiedDate;
  12. import org.springframework.data.jpa.domain.support.AuditingEntityListener;
  13.  
  14. @MappedSuperclass
  15. @EntityListeners(AuditingEntityListener.class)
  16. public abstract class BaseModel {
  17.  
  18. @Id
  19. @GeneratedValue(strategy = GenerationType.AUTO)
  20. protected Long id;
  21.  
  22. @CreatedDate
  23. private Long createTimestamp;
  24.  
  25. @LastModifiedDate
  26. private Long updateTimestamp;
  27.  
  28. @Version
  29. private Long version;
  30.  
  31. public Long getId() {
  32. return id;
  33. }
  34.  
  35. public void setId(Long id) {
  36. this.id = id;
  37. }
  38.  
  39. public Long getCreateTimestamp() {
  40. return createTimestamp;
  41. }
  42.  
  43. public void setCreateTimestamp(Long createTimestamp) {
  44. this.createTimestamp = createTimestamp;
  45. }
  46.  
  47. public Long getUpdateTimestamp() {
  48. return updateTimestamp;
  49. }
  50.  
  51. public void setUpdateTimestamp(Long updateTimestamp) {
  52. this.updateTimestamp = updateTimestamp;
  53. }
  54.  
  55. public Long getVersion() {
  56. return version;
  57. }
  58.  
  59. public void setVersion(Long version) {
  60. this.version = version;
  61. }
  62.  
  63. }

需要说明的是需要在SpringBoot启动类上面添加@EnableJpaAuditing注解

Hibernate学习笔记:基础模型类的更多相关文章

  1. Google Guava学习笔记——基础工具类Joiner的使用

    Guava 中有一些基础的工具类,如下所列: 1,Joiner 类:根据给定的分隔符把字符串连接到一起.MapJoiner 执行相同的操作,但是针对 Map 的 key 和 value. 2,Spli ...

  2. Google Guava学习笔记——基础工具类针对Object类的使用

    Guava 提供了一系列针对Object操作的方法. 1. toString方法 为了方便调试重写toString()方法是很有必要的,但写起来比较无聊,不管如何,Objects类提供了toStrin ...

  3. Google Guava学习笔记——基础工具类Preconditions类的使用

    Preconditions类是一组静态方法用来验证我们代码的状态.Preconditons类很重要,它能保证我们的代码按照我们期望的执行,如果不是我们期望的,我们会立即得到反馈是哪里出来问题,现在我们 ...

  4. Google Guava学习笔记——基础工具类String处理类的使用

    不管你喜欢何种编程语言,很多时候针对string编程的处理都是乏味而且爱出错误的,很多时候,我们需要从文件或是数据库中读取数据,或者根据需求重新格式化或排序字符串给用户显示.幸运的是,Guava提供了 ...

  5. Google Guava学习笔记——基础工具类Splitter的使用

    另一项经常对字符串的操作就是根据指定的分隔符对字符串进行分隔.我们基本上会使用String.split方法: String testString = "Monday,Tuesday,,Thu ...

  6. Hibernate学习笔记(一)

    2016/4/18 19:58:58 Hibernate学习笔记(一) 1.Hibernate框架的概述: 就是一个持久层的ORM框架. ORM:对象关系映射.将Java中实体对象与关系型数据库中表建 ...

  7. Hibernate学习笔记-Hibernate HQL查询

    Session是持久层操作的基础,相当于JDBC中的Connection,通过Session会话来保存.更新.查找数据.session是Hibernate运作的中心,对象的生命周期.事务的管理.数据库 ...

  8. JVM学习笔记——内存模型篇

    JVM学习笔记--内存模型篇 在本系列内容中我们会对JVM做一个系统的学习,本片将会介绍JVM的内存模型部分 我们会分为以下几部分进行介绍: 内存模型 乐观锁与悲观锁 synchronized优化 内 ...

  9. Hibernate学习笔记(二)

    2016/4/22 23:19:44 Hibernate学习笔记(二) 1.1 Hibernate的持久化类状态 1.1.1 Hibernate的持久化类状态 持久化:就是一个实体类与数据库表建立了映 ...

  10. Hibernate 学习笔记一

    Hibernate 学习笔记一 今天学习了hibernate的一点入门知识,主要是配置domain对象和表的关系映射,hibernate的一些常用的配置,以及对应的一个向数据库插入数据的小例子.期间碰 ...

随机推荐

  1. JVisual 相关help参数

    The launcher has determined that the parent process has a console and will reuse it for its own cons ...

  2. Python基础之列表及元组的增删改查

    定义一个列表 晚上的状态不太适合写博客,容易犯困~ 列表的增加有三种方式 第一种主流的增加 append函数 list1 = ['noevil', 'fordearme', 'city', 'cust ...

  3. 解决谷歌浏览器频繁出现adobe flash player因过期而遭到阻止的问题(转自知乎)

    作者:在战争中链接:https://www.zhihu.com/question/32223811/answer/128088278来源:知乎著作权归作者所有,转载请联系作者获得授权. 很多新用户在安 ...

  4. 用photoshop 把视频镜头做成GIF图片

    https://jingyan.baidu.com/article/47a29f2432e113c0142399b0.html

  5. CentOS 下搭建Jenkins

    1.下载安装包 A 可以连接外网: 导入仓库 wget -O /etc/yum.repos.d/jenkins.repo http://pkg.jenkins.io/redhat-stable/jen ...

  6. Python+Selenium学习--窗口切换及操作元素

    场景 有时候我们在测试一个web 应用时会出现多个浏览器窗口的情况,在selenium1.0 中这个问题比较难处理.webdriver 提供了相关相方法可以很轻松的在多个窗口之间切换并操作不同窗口上的 ...

  7. swift - 百度地图API集成

    1.百度搜索  百度地图api 2. 选中之后选择, 看功能需求下载 API 3. 下载的API拖入项目,此处有坑, 如果只用地图或者 定位,这中写着 是 导航的SDK 别拖进去, 不然报错 怕搞错到 ...

  8. 一分钟了解mongodb(转)

    mongo的由来 截取自英文俚语humongous,意为”巨大的”,是否表明mongodb在设计之初就是为大数据量处理而生呢? mongodb是个啥 mongodb是个可扩展.高性能.开源.面向文档( ...

  9. stark组件开发之自动生成URL

    app01\model.py from django.db import models # Create your models here. class Depart(models.Model): i ...

  10. Repeater控件添加序号列

    在项目开发过程中,会经常遇到ASP.NET repeater控件添加序号列,有些新手可能还不会,网上搜集整理了一些,需要的朋友可以参考下 ASP.NET repeater添加序号列的方法 1.< ...