hibernate连接SqlServer2000的有关问题
hibernate连接SqlServer2000的问题
实体对象:Employee.java:
对象关系映射文件:Employee.hbm.xml
sqlserver建表语句:
增加一条记录,测试代码:
报错:
Hibernate: insert into employee (e_name, e_email) values (?, ?) select scope_identity()
Exception in thread "main" org.hibernate.exception.GenericJDBCException: could not insert: [com.zmj.domain.Employee]
...
Caused by: java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC][SQLServer]无法将 NULL 值插入列 'e_id',表 'sshTest1.dbo.employee';该列不允许空值。INSERT 失败。
我是新手,请大家帮帮忙,谢谢了。
实体对象:Employee.java:
public class Employee {
private Integer e_id;
private String e_name;
private String e_email;
getters();....
setters();....
}
对象关系映射文件:Employee.hbm.xml
<hibernate-mapping package="com.zmj.domain">
<class name="Employee" table="employee">
<id name="e_id" column="e_id" type="java.lang.Integer">
<generator class="native"></generator>
</id>
<property name="e_name" column="e_name" type="java.lang.String"/>
<property name="e_email" column="e_email" type="java.lang.String"/>
</class>
</hibernate-mapping>
sqlserver建表语句:
create table employee(
e_id integer primary key,
e_name varchar(64),
e_email varchar(64),
)
增加一条记录,测试代码:
Employee e = new Employee();
e.setE_email("aa@163.com");
e.setE_name("aa");
e.setE_id(1);
session.save(e);
transaction.commit();
session.close();
报错:
Hibernate: insert into employee (e_name, e_email) values (?, ?) select scope_identity()
Exception in thread "main" org.hibernate.exception.GenericJDBCException: could not insert: [com.zmj.domain.Employee]
...
Caused by: java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC][SQLServer]无法将 NULL 值插入列 'e_id',表 'sshTest1.dbo.employee';该列不允许空值。INSERT 失败。
我是新手,请大家帮帮忙,谢谢了。
hibernate
Hibernate
- 1为啥有的方法里面throw new 自定义错误类("") 外的方法外面有throws 有的没有
- 2表单提交的时分保存和返回只要两个图片就好了吗 不要具体的方法
- 3JS如何实现页面按空格键的时候自动替换成‘’
- 4hibernate更动字段not null属性不生效
- 5hibernate多对多HQL查询的不解 各位大牛来指点一下吧
- 6jquery如何样按顺序获取SRC的属性和文本框的值
- 7action里面对数据库一系列操作 如何保证原子性呢
- 8You have an error in your SQL syntax 找了一晚上不知道错哪了
- 9大家伙儿hibernate 的项目里用一级缓存和二级缓存吗
- 10PreparedStatement的批量插入式无序的?该如何处理
文章评论
相关解决方案