最新文章专题视频专题问答1问答10问答100问答1000问答2000关键字专题1关键字专题50关键字专题500关键字专题1500TAG最新视频文章推荐1 推荐3 推荐5 推荐7 推荐9 推荐11 推荐13 推荐15 推荐17 推荐19 推荐21 推荐23 推荐25 推荐27 推荐29 推荐31 推荐33 推荐35 推荐37视频文章20视频文章30视频文章40视频文章50视频文章60 视频文章70视频文章80视频文章90视频文章100视频文章120视频文章140 视频2关键字专题关键字专题tag2tag3文章专题文章专题2文章索引1文章索引2文章索引3文章索引4文章索引5123456789101112131415文章专题3
当前位置: 首页 - 科技 - 知识百科 - 正文

hibernate自定义UUID(mysqluuid_short)_MySQL

来源:动视网 责编:小采 时间:2020-11-09 18:33:34
文档

hibernate自定义UUID(mysqluuid_short)_MySQL

hibernate自定义UUID(mysqluuid_short)_MySQL:Hibernate bitsCN.com UUID生成类 3 import org.apache.commons.logging.Log; 4 import org.apache.commons.logging.LogFactory; 5 import org.hibernate.HibernateException; 6 import org.h
推荐度:
导读hibernate自定义UUID(mysqluuid_short)_MySQL:Hibernate bitsCN.com UUID生成类 3 import org.apache.commons.logging.Log; 4 import org.apache.commons.logging.LogFactory; 5 import org.hibernate.HibernateException; 6 import org.h


Hibernate

bitsCN.com

UUID生成类

 3 import org.apache.commons.logging.Log; 4 import org.apache.commons.logging.LogFactory; 5 import org.hibernate.HibernateException; 6 import org.hibernate.MappingException; 7 import org.hibernate.dialect.Dialect; 8 import org.hibernate.engine.SessionImplementor; 9 import org.hibernate.exception.JDBCExceptionHelper;10 import org.hibernate.id.Configurable;11 import org.hibernate.id.IdentifierGenerator;12 import org.hibernate.type.Type;13 14 import java.io.Serializable;15 import java.sql.PreparedStatement;16 import java.sql.ResultSet;17 import java.sql.SQLException;18 import java.util.Properties;19 20 /**21 * Created with IntelliJ IDEA.22 * User: Administrator23 * Date: 13-5-824 * Time: 下午6:1525 * To change this template use File | Settings | File Templates.26 */27 public class ShortUUIDIncrementGenerator implements IdentifierGenerator, Configurable {28 private static final Log log = LogFactory.getLog(ShortUUIDIncrementGenerator.class);29 private final String sql = "select uuid_short()";30 31 @Override32 public Serializable generate(SessionImplementor sessionImplementor, Object o) throws HibernateException {33 synchronized (this) {34 try {35 PreparedStatement st = sessionImplementor.getBatcher().prepareSelectStatement(sql);36 try {37 ResultSet rs = st.executeQuery();38 final long result;39 try {40 rs.next();41 result = rs.getLong(1);42 } finally {43 rs.close();44 }45 log.debug("GUID identifier generated: " + result);46 return result;47 } finally {48 sessionImplementor.getBatcher().closeStatement(st);49 }50 } catch (SQLException e) {51 throw JDBCExceptionHelper.convert(52 sessionImplementor.getFactory().getSQLExceptionConverter(),53 e,54 "could not retrieve GUID",55 sql56 );57 }58 }59 }60 61 @Override62 public void configure(Type type, Properties properties, Dialect dialect) throws MappingException {63 //To change body of implemented methods use File | Settings | File Templates. }65 66 }

配置:

 @Id @GeneratedValue(generator = "shortUid") @GenericGenerator(name = "shortUid", strategy = "com.up72.msi.util.ShortUUIDIncrementGenerator") @Column(name = "id", unique = true, nullable = false, insertable = true, updatable = true, length = 19) public java.lang.Long getId() {
bitsCN.com

文档

hibernate自定义UUID(mysqluuid_short)_MySQL

hibernate自定义UUID(mysqluuid_short)_MySQL:Hibernate bitsCN.com UUID生成类 3 import org.apache.commons.logging.Log; 4 import org.apache.commons.logging.LogFactory; 5 import org.hibernate.HibernateException; 6 import org.h
推荐度:
标签: mysql mysq Hibernate
  • 热门焦点

最新推荐

猜你喜欢

热门推荐

专题
Top