hibernate提交事务时报如下错误:
Caused by: org.hibernate.HibernateException:
identifier of an instance of user is alterde from from 41 to 43。
导致该错误的代码如下:
private User user = new Usesr();
public void save(){
Session session=HibernateSessionFactory.getSession();
Transaction tx = null;
try {
tx = session.beginTransaction();
session.saveOrUpdate(user);
tx.commit();
} catch (HibernateException e) {
tx.rollback();
log.error("Error: " + e.getMessage());
}
}
导致该错误的原因:
在使用seam框架中将一个action类的上下文范围定义page范围,访问一个注册页面,
添加注册信息,调用该action类保存后,如果页面还是返回到注册页面(即返回到原页面),
当再次填写注册信息保存时,由于该action类的上下文范围是page范围,上一次保存的user对象还存在,
导致再次保存user对象提交事务插入时hibernate认为第二次保存的对象与之前的对象是同一个对象,之前的主键被更新,因此报错。
解决办法:
在每次提交事务后再立即新建一个对象。
正确的代码如下:
private User user = new Usesr();
public void save(){
Session session=HibernateSessionFactory.getSession();
Transaction tx = null;
try {
tx = session.beginTransaction();
session.saveOrUpdate(user);
tx.commit();
user = new User();
} catch (HibernateException e) {
tx.rollback();
log.error("Error: " + e.getMessage());
}
}
导致该错误的其它原因可能还有:
hibernate hbm里面id的type和java文件里面的不一致!
分享到:
相关推荐
The "Identifier Case Sensitive" check box, which enables case-sensitive processing of database object identifier names, is added to MySQL Server Options The documentation generation for Enum members ...
- ADD: Add TFlexPanel.InvalidateControl virtual method which calls from TFlexControl.Invalidate and can be overriden (it is possible now to catch all object invalidation calls). - FIX: The TFlexPanel....
This research work is carried out within the framework of the PRAXITELE project which aims to develop a future-oriented urban transportation system based on a fleet of electric computer-driven ...
Wifi (802.11) In a wireless LAN, wireless users transmit/receive packets to/from an base station (i.e., wireless access point) within a radius of few tens of meters. The base station is typically ...
Each index row in node pages contains an index key (or set of keys for a composite index) and a pointer to a page at the next level for which the first key value is the same as the key value in the ...
Modified so that when cursor is changed to hourglass by VCLZip, previous cursor is saved correctly instead of just changing it back to default cursor. Now saves Central Directory Extra Fields ...
All resources, including files and Registry keys, that one user has access to, the other will as well.Another instance where duplicate SIDs can cause problems is where there is removable media ...
A FilterChain is an object provided by the servlet container to the developer giving a view into the invocation chain of a filtered request for a resource. FilterConfig - interface javax.servlet....
An isolation level determines the degree to which data is isolated for use by one process and guarded against interference from other processes. Prior to SQL Server 7.0, REPEATABLE READ and ...
错误:L6238E:os_cpu_a.o(subr) contains invalid call from '~PRES8 (The user did not require code to preserve 8-byte aligment of 8-byte data objects)' function to 'REQ8 (Codewas permitted to depend on ...
* when demuxing subtitle files, the number of captions is added to the filename * timestamp derived FPS is used for gap checking instead of video bitstream FPS * fixed: 44.1khz AC3 encoding was still ...
- **`identify(element)`**: Assigns a unique identifier to an element. - **`immediateDescendants`**: Retrieves immediate child elements. - **`insert(element, {position: content})`**: Inserts content ...
We choose to install Odoo in an Ubuntu host, but guidance is given to have a perfectly functioning development environment in a Windows machine with an Ubuntu virtual machine. Chapter 3, Your First ...
1.2.3.4.3 SFN for point to point services..............................................25 1.2.3.5 The Frequency Bands Intended for LTE.......................................26 1.2.3.5.1 Exclusive ...
of which is terminated by a single 0x00 octet. All extension identifiers are case sensitive. Examples of URIs: http://www.aescrypt.com/extensions/creator/ urn:oid:1.3.6.1.4.1.17090.55.14 urn:...
applications has led to requirements that the assignment of message identifiers to communication functions be standardized for certain applications. These applications can be realized with CAN more ...
The user can enter a number to each of the two textinput boxes, then click/tap either of the four images of mathematical operators. Once clicked, it should display a correct answer on the screen. 1. ...
Can not go back to a wrapped value.Term Offset: Identifier of a single byte within the Term. Always start at 0. This is the number of the byte within a given term starting from the beginning.Frame...
The primary objective of CUCU is to serve as an educational tool for those interested in understanding how compilers work. By creating a simplified version of a C compiler, the author aims to ...