熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> Java編程 >> Java開源技術 >> 正文

hibernate中自定義主鍵生成器[2]

2022-06-13   來源: Java開源技術 

public void configure(Type type Properties params Dialect d) throws MappingException {
String table = paramsgetProperty(table);
if (table==null) table = paramsgetProperty(PersistentIdentifierGeneratorTABLE);
String column = paramsgetProperty(column);
if (column==null) column = paramsgetProperty(PersistentIdentifierGeneratorPK);
String schema = paramsgetProperty(PersistentIdentifierGeneratorSCHEMA);
sql = select max(+column +) from + ( schema==null ? table : schema + + table );
loginfo(sql);
}

private void getNext(Connection conn) throws HibernateException {
try {
PreparedStatement st = connprepareStatement(sql);
ResultSet rs = stexecuteQuery();
if ( rsnext() ) {
next = rsgetLong() + ;
}
else {
next = l;
}
}catch(SQLException e)
{
throw new HibernateException(e);
}
finally {
try{
connclose();
}catch(SQLException e)
{
throw new HibernateException(e);
}
}
}
}


  配置:

  在對應的hbm文件裡面將id的配置如下:

<id name=id type=long column=id >
<generator class=hibernateIncrementGenerator />
</id>

 

[]  []  


From:http://tw.wingwit.com/Article/program/Java/ky/201311/29168.html
    推薦文章
    Copyright © 2005-2022 電腦知識網 Computer Knowledge   All rights reserved.