hibernate下做one-to-one主键关联时候出现问题(50分)
2个表t_user、t_passport各有一个id字段设为主键,t_passport的id还是外键,引用t_user的id
Tuser user=new Tuser();
user.setTel("123");
user.setAddr("langfang");
Tpassport passport=new Tpassport();
passport.setSerial("PCN759386");
passport.setExpiry(new Integer(20080101));
passport.setTuser(user);
user.setTpassport(passport);
try{
Transaction tx=session.beginTransaction();
session.save(user);
tx.commit();
}catch(Exception e){
System.out.println("save:"+e.toString());
}
提示:ERROR TableGenerator:104 - could not read a hi value
java.sql.SQLException: 第 1 行: FOR UPDATE 子句仅允许用于 DECLARE CURSOR。
问题点数:10、回复次数:12Top
1 楼leonyuann(舞月光)回复于 2005-06-15 15:53:28 得分 0
到下面地址领分:
http://community.csdn.net/Expert/topic/3808/3808318.xml?temp=.7261164
http://community.csdn.net/Expert/topic/3984/3984472.xml?temp=.9426081
http://community.csdn.net/Expert/topic/3887/3887081.xml?temp=.5927393Top
2 楼areshong(strength&honor)回复于 2005-06-15 16:34:18 得分 0
把xml文件拿来看一下Top
3 楼leonyuann(舞月光)回复于 2005-06-15 17:26:26 得分 0
Tuser.hbm.xml:
<id
name="id"
type="java.lang.Integer"
column="id"
>
<generator class="native" />
</id>
.....
<one-to-one
name="tpassport"
class="org.hibernate.sample.Tpassport"
cascade="all"
outer-join="auto"
>
</one-to-one>
Top
4 楼leonyuann(舞月光)回复于 2005-06-15 17:27:35 得分 0
Tpassport.hbm.xml:
<id
name="id"
type="java.lang.Integer"
column="id"
>
<generator class="foreign">
<param name="property">tuser</param>
</generator>
</id>
.....
<one-to-one
name="tuser"
class="org.hibernate.sample.Tuser"
outer-join="auto"
constrained="true"
>
</one-to-one>
Top
5 楼areshong(strength&honor)回复于 2005-06-16 00:19:49 得分 10
问题好像在<generator class="native" />这里
native根据底层数据库对自动生成标志符的支持能力,来选择使用identity、sequence或hilo。可能你数据库的这个字段既不支持identity,又不支持sequence,系统指定hilo结果报错了
看你的意思应该是<generator class="assigned" />吧
Top
6 楼leonyuann(舞月光)回复于 2005-06-16 08:38:56 得分 0
数据库是sql server,肯定支持identity呀Top
7 楼leonyuann(舞月光)回复于 2005-06-16 08:44:08 得分 0
好像是不支持,我换<generator class="identity" />后,提示Dialect does not support identity key generation
Top
8 楼leonyuann(舞月光)回复于 2005-06-16 08:48:12 得分 0
我在hibernate.cfg.xml中设的dialect为:
<!--dialect-->
<property name="hibernate.connection.dialect">
net.sf.hibernate.dialect.SQLServerDialect
</property>
有什么错误吗Top
9 楼bluelily22(丁丁)回复于 2005-06-16 09:03:55 得分 0
如果你数据库里ID设为Identity ,那肯定支持的,
看到提示Dialect Dialect does not support identity key generation
你要看一看你的数据库方言是不是指定为sql
<property name="dialect">
net.sf.hibernate.dialect.SQLServerDialect
</property>Top
10 楼leonyuann(舞月光)回复于 2005-06-16 09:07:47 得分 0
我设的没有错啊,怎么回事?Top
11 楼areshong(strength&honor)回复于 2005-06-16 09:34:48 得分 0
数据库支持identity,也要你在数据库中把相关字段设成identity的,确认一下是不是设了
若换成<generator class="identity" />还报错的话,真是不知道说什么好了
还有,你的jdbc是怎么设的,如果用odbc桥的话,用纯jdbc的试试,我有一次遇到莫名其妙的问题,就是这个引起的
Top
12 楼leonyuann(舞月光)回复于 2005-06-16 10:01:51 得分 0
sql server中当然设置了id字段为标识字段,没有问题!
我的库driver为net.sourceforge.jtds.jdbc.DriverTop





