使用Hibernate连接derby数据库,其中student表中S_id是表的主键,以及takes等表的外键。
在执行插入命令时提示如下:
其中student/hbm/xml文件配置如下:
student操作的工具类:
使用Hibernate连接derby数据库,其中student表中S_id是表的主键,以及takes等表的外键。
在执行插入命令时提示如下:
student操作的工具类:
解决方法1
在数据库中把S_ID设置成自动生成
例:
ALTER TABLE student DROP COLUMN s_id;
ALTER TABLE student add s_id int identity(1,1);
解决方法2
hbm文件中,把S_ID当做普通的列来配置,不用主键生成策略等。