hibernate 自定义UUID(mysql uuid_short)
来源:互联网 发布:windows上安装jenkins 编辑:程序博客网 时间:2024/05/18 00:56
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.64 }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() {
0 0
- hibernate 自定义UUID(mysql uuid_short)
- MySQL内置函数uuid和uuid_short
- MySQL的server_uuid获取之uuid()函数和uuid_short()函数
- mysql uuid
- 用mysql UUID()函数生成自定义的MYUUID()函数
- hibernate中使用uuid
- hibernate uuid
- Hibernate UUID生成配置
- hibernate oracle 配置uuid
- Hibernate UUID 生成策略
- JS生成自定义uuid
- Mysql的UUID
- Mysql的UUID
- Mysql 存储 UUID
- MySQL UUID函数详解
- MySQL uuid的使用
- mysql uuid以及gtid
- mysql中使用UUID
- ORA-27125 解决方法<转>
- android html 读写文件
- com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
- IDEA 自动生成serialVersionUID
- Windows下MySQL UTF8 编码设置(解决中文乱码)
- hibernate 自定义UUID(mysql uuid_short)
- Mac Intellij 控制台乱码解决
- JRebel 5.3.2
- jetty属性
- Can't find file: './mysql/plugin.frm' (errno: 13)[mysql数据目录迁移错位]错误解决
- Android解析JASON方式
- DOM解析XML文件
- 安装和使用memcached
- cocos2d-x-3.0rc0 项目创建