staff表主码为ID,引用department表的DEPARTMENT_ID作为外码,向staff中插入数据时,报异常为sequence不存在,但是NEWID这个sequence我是建了的。怎么回事呢,hibernate配置文件如下<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="com.liyanframework.demo.domain">
<class name="Staff" table="STAFF">
<id name="id" type="java.lang.Long">
<column name="ID" precision="22" scale="0" />
<generator class="sequence">
<param name="NEWID"></param>
</generator>
</id>
<property name="name" column="NAME" type="string" />
<property name="age" column="AGE" type="integer" />
<property name="birthday" column="BIRTHDAY" type="date" />
<property name="salary" column="SALARY" type="big_decimal" />
<property name="level" column="LEVELNESS" type="float" />
<property name="createTime" column="CREATETIME" type="timestamp" />
<property name="enable" column="ENABLE" type="character" />
<property name="status" column="STATUS" type="string" />
<many-to-one name="department" column="DEPARTMENT_ID" class="Department" />
</class>
</hibernate-mapping>另外想要设置DEPARTMENT_ID 的值是不是这样:
Staff staff = new Staff();
Department department = new Department ();
department.setDepartmentId(XXX);
staff.setDepartment(department);我觉得有可能就是这几行代码导致的错误。
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="com.liyanframework.demo.domain">
<class name="Staff" table="STAFF">
<id name="id" type="java.lang.Long">
<column name="ID" precision="22" scale="0" />
<generator class="sequence">
<param name="NEWID"></param>
</generator>
</id>
<property name="name" column="NAME" type="string" />
<property name="age" column="AGE" type="integer" />
<property name="birthday" column="BIRTHDAY" type="date" />
<property name="salary" column="SALARY" type="big_decimal" />
<property name="level" column="LEVELNESS" type="float" />
<property name="createTime" column="CREATETIME" type="timestamp" />
<property name="enable" column="ENABLE" type="character" />
<property name="status" column="STATUS" type="string" />
<many-to-one name="department" column="DEPARTMENT_ID" class="Department" />
</class>
</hibernate-mapping>另外想要设置DEPARTMENT_ID 的值是不是这样:
Staff staff = new Staff();
Department department = new Department ();
department.setDepartmentId(XXX);
staff.setDepartment(department);我觉得有可能就是这几行代码导致的错误。
解决方案 »
- 「100分」ajax传值问题
- struts2 OGNL:jsp页面中session键值是变量,如何用ognl表达式取出session中对象值。
- 这段代码注释是啥意思啊
- struts2 ajax请求action调用路径问题
- struts中ApplicationResources.properties文件的{0}{1}{2}...
- 利用CDMA无线上网能实现远程访问SQLSERVER数据库吗?(在线等)
- 请问一个java的问题
- 安装了j2ee的jdk,还用再装j2se吗?
- 用j2ee要精通corba吗?欢迎讨论
- 位运算问题:为什么-1>>3 = -1,-1>>>3 = 536870911?
- Invalid byte 2 of 2-byte UTF-8 sequence
- java注解@Resource机制如何取到注入过的Bean
department.setDepartmentId(XXX);就不要设置sequence了,应该是assigned
<generator class="sequence">
<param name="sequence">序列名< /param>
</generator>
</id>
这里 错了,应该是:
<param name="sequence">ID</param>name指定的是 主键的生成策略,具体值放 后面即可。