mybatis 中设置useGeneratedKeys="false"执行就报不支持的特性
想学习一下mybatis,我用spring+mybatis,数据库oracle,id用自增长的sequence,想插入数据后获取到id的值,以供其他表使用,可是在xml中配置 useGeneratedKeys="false" 就报不支持的特性,改为true就可用。
这样是可用的
XML code
<insert id="insertProduct" parameterType="Test" keyProperty="id" useGeneratedKeys="true" >
INSERT INTO myd_user (id,name)
VALUES (seq_test.nextval, #{name})
</insert>
这样不可用
XML code
<insert id="insertProduct" parameterType="Test" keyProperty="id" useGeneratedKeys="false" >
INSERT INTO myd_user (id,name)
VALUES (#{id}, #{name})
</insert>
如果把false改成true也可用,大侠们帮帮忙啊,不这么写也可以,能获取到插入的id就行,但是我不想把SqlSessionFactory写到代码里,我把他写配置文件里了,[code=XML][<context:annotation-config></context:annotation-config>
<context:component-scan base-package="*"></context:component-scan>
<mvc:annotation-driven />
<!-- enable autowire -->
<context:annotation-config />
<!-- enable transaction demarcation with annotations -->
<tx:annotation-driven />
<bean id="dataSource" class="org.logicalcobwebs.proxool.ProxoolDataSource" ><!-- 配置连接池 -->
<property name="driver" value="oracle.jdbc.driver.OracleDriver"></property>
<property name="driverUrl" value="jdbc:oracle:thin:@192.168.0.202:1521:orcl"></property>
<property name="user" value="priv"></property>
<property name="password" value="priv"></property>
</bean>
<!-- transaction manager, use JtaTransactionManager for global tx -->
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource" />
</bean>
<!-- define the SqlSessionFactory -->
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="typeAliasesPackage" value="com.mypriv.vo" />
</bean>
<!-- scan for mappers and let them be autowired -->
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="com.mypriv.dao" />
</bean>/code]
------解决方案--------------------
看到了,我也希望能看到答案