惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

GbyAI
GbyAI
Simon Willison's Weblog
Simon Willison's Weblog
Microsoft Security Blog
Microsoft Security Blog
Y
Y Combinator Blog
The GitHub Blog
The GitHub Blog
Engineering at Meta
Engineering at Meta
F
Fortinet All Blogs
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
A
About on SuperTechFans
Last Week in AI
Last Week in AI
月光博客
月光博客
有赞技术团队
有赞技术团队
P
Proofpoint News Feed
MyScale Blog
MyScale Blog
Martin Fowler
Martin Fowler
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
C
Check Point Blog
U
Unit 42
The Register - Security
The Register - Security
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Hugging Face - Blog
Hugging Face - Blog
阮一峰的网络日志
阮一峰的网络日志
V
Visual Studio Blog
酷 壳 – CoolShell
酷 壳 – CoolShell
D
DataBreaches.Net
WordPress大学
WordPress大学
aimingoo的专栏
aimingoo的专栏
H
Hacker News: Front Page
Recent Announcements
Recent Announcements
C
CXSECURITY Database RSS Feed - CXSecurity.com
Latest news
Latest news
小众软件
小众软件
P
Palo Alto Networks Blog
PCI Perspectives
PCI Perspectives
Security Latest
Security Latest
S
Secure Thoughts
Scott Helme
Scott Helme
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
T
Threat Research - Cisco Blogs
P
Proofpoint News Feed
M
MIT News - Artificial intelligence
Application and Cybersecurity Blog
Application and Cybersecurity Blog
Google DeepMind News
Google DeepMind News
Recorded Future
Recorded Future
O
OpenAI News
S
Securelist
云风的 BLOG
云风的 BLOG
H
Help Net Security
T
Troy Hunt's Blog

博客园 - micenter

Register ASP.NET 4.0 An error has occurred: 0x8007b799 You must have administrative rights on this machine in order to ru 记录一些常用的SQLServer时间日期函数详解 IT民工的2013生活创想 SQL 日志太大,脚本清除 跟随博客园进入2012 .NET 中 操作excel 系列--copy功能. .NET 中 操作excel 系列--导入与导出. 设置VSS2005使支持通过Internet访问 中the server configuration settings apply only for local databases....问题解决 vss 2005 配置服务器端的时候提示"IIS没有安装" ASP.NET MVC 实现二级域名 [转] Eclipse快捷键大全(转载) Android单元测试测试[转] 手动使用EDM 生成器 (EdmGen.exe) 工具生成 SSDL,CSDL,MSL 文件。 InnoDB ,MyISAM 等存储引擎中主外键的大小设置. 在 mysql 中 定义 数据库,表,列时,设定的各个的编码格式。 asm.jar 等包的重用问题之解决方案 汇总 Hibernate 与 jdbc,jndi+dbcp, proxool ,c3p0 连接池的配置 - micenter Hibernate中自动增长列的 在Annotations 中的配置和数据库设置默认值问题 - micenter java 字符串的编码与C#的区别 - micenter - 博客园
Hibernate中自动增长列的..hbm.xml 配置和数据库设置默认值问题 - micenter - 博客园
micenter · 2009-12-11 · via 博客园 - micenter

    在Hibernate中的映射文件配置中, 如果在数据库中设置一列为自动增长列,但又不是主键,则在配置时需要设置 property 节点的 "insert" 和“update” 属性为false. 即: <property column="ID" name="id" type="int" insert="false" update="false"/> 否则会出现 “ com.microsoft.sqlserver.jdbc.SQLServerException: Cannot insert explicit value for identity column in table 'Users' when IDENTITY_INSERT is set to OFF.” 这样的异常(Users为表名其中有一个ID的列为自动增长)

其生成的SQL语句为 “insert into Users (ID, Password, Sex, Age, Phone, UserName) values (?, ?, ?, ?, ?, ?)”。

将 "insert" 和“update” 属性改为“false” 后,其生成的SQL语句为:

“insert into Users (Password, Sex, Age, Phone, UserName) values (?, ?, ?, ?, ?)”。

ID列会按照数据库的设置去赋值。

其原理是在插入和更新的时候不会接收从客户端提交上去的数据。生成的SQL 语句中会自动将这一列去掉。同理,若想在数据库中给某列设置默认值,只需设置 <class name="lec.data.entity.User" table="Users" dynamic-insert="true" dynamic-update="true">  即将“dynamic-insert”和“dynamic-update”设置为“true”  或者 设置 <property column="***" name="***" type="int" insert="false" update="false"/>