Using UUID in spring data JPA

Source: Internet
Author: User

How to define a uuid in an entity, needless to say

defined in the Entity public class Baseentity.java

import javax.persistence.generatedvalue;import javax.persistence.id;import  javax.persistence.mappedsuperclass;import org.hibernate.annotations.genericgenerator;import  org.springframework.data.domain.persistable;import org.apache.commons.lang3.builder.tostringbuilder; import org.apache.commons.lang3.builder.tostringstyle;/** *  entity public class, all entities inherit the object  * @ author youway */@MappedSuperclasspublic  abstract class baseentity implements  persistable<string> {private static final long serialversionuid =  1L; @Id @generatedvalue (generator =  "System-uuid") @GenericGenerator (name =  " System-uuid ", strategy = " UUID ") Private string id;public string getid ()  {return id;} Protected void setid (Final string id)  {this.id = id;} Public boolean isnew ()  {return this.id ==&Nbsp;null;} /** *  overrides the ToString method to show all JavaBean attribute values, omitting to write a lot of getxxx methods  */@Overridepublic  String  ToString ()  {return tostringbuilder.reflectiontostring (This,tostringstyle.multi_line_style);} @Overridepublic  boolean equals (object obj)  {if  (obj == null)  {return  false;} if  (This == obj)  {return true;} if  (!getclass (). Equals (Obj.getclass ()))  {return false;} baseentity rhs =  (baseentity)  obj;return this.id == null ? false  : this.id.equals (rhs.id);}}



Using UUID in spring data JPA

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.