自定义JPA主键生成策略实现保存时允许自定义ID


自定义JPA主键生成策略实现保存时允许自定义ID

参考: https://www.jianshu.com/p/db5f10b546df

 1 public class CustomUUIDGenerator extends UUIDGenerator {
 2     @Override
 3     public Serializable generate(SessionImplementor session, Object object) throws HibernateException {
 4         if (object == null){
 5             throw new HibernateException(new NullPointerException());
 6         }
 7         String id = ((CarLocationLevel) object).getId();
 8         if (StringUtils.isBlank(id)) {
 9             return super.generate(session, object).toString().replaceAll("-", "") ;
10         } else {
11             return id;
12         }
13     }
14 }

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM