JPA基类


JPA基类是什么?使用场景?

@MapperSuperClass

被该注解修饰的类,是JPA Entity基类的标识。

@GenericGenerator(name = "system-uuid", strategy = "uuid")

声明策略通用生成器,name为"system-uuid",策略strategy为"uuid"。

@GeneratedValue(generator = "system-uuid")

用generator属性指定要使用的策略生成器。

代码示例

@MappedSuperclass
public abstract class IdEntity {

   protected String id;

   @Id
   @GeneratedValue(generator = "system-uuid")
   @GenericGenerator(name = "system-uuid", strategy = "uuid")
   @Column(length = 55)
   public String getId() {
      return id;
   }

   public void setId(String id) {
      this.id = id;
   }

}