[AppleScript] 纯文本查看 复制代码
package core.util;
import java.io.Serializable;
import java.text.SimpleDateFormat;
import java.util.Date;
import org.hibernate.HibernateException;
import org.hibernate.engine.spi.SessionImplementor;
import org.hibernate.id.IdentifierGenerator;
import org.hibernate.persister.entity.AbstractEntityPersister;
public class IdGenerator implements IdentifierGenerator{
private SimpleDateFormat preFix = new SimpleDateFormat("yyyyMMdd");
@Override
public Serializable generate(SessionImplementor session, Object object) throws HibernateException {
//持久化对象
AbstractEntityPersister classMetadata =
(AbstractEntityPersister)session.getFactory()
.getClassMetadata(object.getClass());
String tableName = classMetadata.getTableName();//表名
tableName = tableName.substring(0,5);
String idString = preFix.format(new Date()) + System.currentTimeMillis() % 99; //时间
return tableName+idString;
}
}