首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > J2EE开发 >

同一事宜 是否能级联插入

2013-07-01 
同一事务 是否能级联插入在同一个事务(相同的Connection对象),好像不能级联插入对象。1.user表discuss表(包

同一事务 是否能级联插入
在同一个事务(相同的Connection对象),好像不能级联插入对象。
1.user表   discuss表(包含 userId键)
代码如下,这样好像不行。
应为user没有commit 不会产生 userId 这样没法级联;

各位大神帮帮忙,怎么解决。


conn = dbcp.getConnection();
conn.setAutoCommit(false);
pstat = conn.prepareStatement(sql);
pstat.setString(1, user.getUsername());
pstat.executeUpdate();

Long id = findUserinfoByUsername(user.getUsername()).getUserId();

pstat = conn.prepareStatement(dsql);
pstat.setLong(1, id);
pstat.setString(2, discuss.getDiscussTable());
pstat.executeUpdate();
[解决办法]
Long id = findUserinfoByUsername(user.getUsername()).getUserId();
你的这个id应该为空,所以后面插入无效。

热点排行