UuidIdentityEntity.java 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. /*******************************************************************************
  2. * Copyright (c) 2005, 2014 springside.github.io
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. *******************************************************************************/
  6. package com.yihu.jw.entity;
  7. import org.hibernate.annotations.GenericGenerator;
  8. import org.springframework.data.jpa.domain.support.AuditingEntityListener;
  9. import javax.persistence.*;
  10. import java.io.Serializable;
  11. /**
  12. * 统一定义id的entity基类.
  13. * 主键生成策略是UUID
  14. * @author calvin
  15. */
  16. // JPA 基类的标识
  17. @MappedSuperclass
  18. @EntityListeners(AuditingEntityListener.class)
  19. public abstract class UuidIdentityEntity implements Serializable {
  20. protected String id; // 非业务主键
  21. @Id
  22. @GeneratedValue(generator = "uuid")
  23. @GenericGenerator(name = "uuid", strategy = "uuid")
  24. @Column(name = "id", unique = true, nullable = false)
  25. public String getId() {
  26. return id;
  27. }
  28. public void setId(String id) {
  29. this.id = id;
  30. }
  31. }