Posted on 2011-05-06 14:24
Kavin 阅读(2686)
评论(0) 编辑 收藏
SSH2中,直接获取SEQUENCE的NEXTVAL
使用Spring的 类 org.springframework.jdbc.support.incrementer.OracleSequenceMaxValueIncrementer
Spring配置文件:
1 <bean id="userDao" class="com.xx.dao.impl.UserDAOImpl">
2 <property name="sessionFactory" ref="sessionFactory" />
3 <property name="seqGenerator" ref="seqDispGenerator"></property>
5 </bean>
6
7 <bean id="seqDispGenerator" class="org.springframework.jdbc.support.incrementer.OracleSequenceMaxValueIncrementer">
8 <property name="dataSource" ref="dataSource"></property>
9 <property name="incrementerName" ><value>SEQ_DISP_ID</value></property>
10 </bean>
UserDAOImpl.java中引用:
private OracleSequenceMaxValueIncrementer seqGenerator;
/**
* @return the seqGenerator
*/
public OracleSequenceMaxValueIncrementer getSeqGenerator() {
return seqGenerator;
}
/**
* @param seqGenerator the seqGenerator to set
*/
public void setSeqGenerator(OracleSequenceMaxValueIncrementer seqGenerator) {
this.seqGenerator = seqGenerator;
}
UserDAOImpl.java中调用:
1 System.out.println("---------------------- this.seqGenerator().nextIntValue="+this.seqGenerator.nextIntValue());