hibernate 中为什么生成的 insert 语句总是少了一个 test_id 字段?

wealth 2005-03-02 05:15:38
hibernate 中为什么生成的 insert 语句总是少了一个 test_id 字段?

<hibernate-mapping>

<class name="test" table="test">
<id name="id" type="int" unsaved-value="0">
<column name="test_id" sql-type="int" not-null="true"/>
<generator class="native"/>
</id>
<property name="name" type="string">
<column name="test_name" sql-type="string" length="100" not-null="true"/>
</property>
</class>

</hibernate-mapping>

自动生成的SQL:

insert into test (test_name) values (?) select scope_id entity()

然后驱动程序报错说 id must not null!

哪里配置错了?
是不是表的id字段一定要设为自增?那这兼容性也不是很好!
...全文
177 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
wealth 2005-03-14
  • 打赏
  • 举报
回复
thanks !
wealth 2005-03-12
  • 打赏
  • 举报
回复
....
lqy169 2005-03-08
  • 打赏
  • 举报
回复
<generator class="assigned"/> 就可以了
wealth 2005-03-07
  • 打赏
  • 举报
回复
还是不行!!???
fashchina 2005-03-02
  • 打赏
  • 举报
回复
<generator class="native"/>
主键的生成方法?/
wealth 2005-03-02
  • 打赏
  • 举报
回复
现在的需要就是,把一条包括全部字段的记录插入到数据库中,

但上面的配置,就是不能在 insert 中生成 test_id 的字段及其值!

不知什么原因???!!!!
flyinrain 2005-03-02
  • 打赏
  • 举报
回复
你应该根据自己的需要来配置id的生成方法。

67,550

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧