关于hibernate加锁的问题?大家进来看一下。
我使用hibernate访问ORACLE9i数据库,首先数据要分页然后要加悲观锁,语句如下:
String hqlStr = "from MessageEntity mes where mes.messageChannel=:mcv ";
quMessage = session.createQuery(hqlStr);
quMessage.setLockMode( "mes ", LockMode.UPGRADE_NOWAIT);
quMessage.setString( "mcv ", mesChannel);
quMessage.setFirstResult(beginNumber);
quMessage.setMaxResults(numberOfEachPage);
运行是报如下错误:
17:20:57,453 INFO [STDOUT] Hibernate: select * from ( select messageent0_.mid as mid0_, messageent0_.MDATE as MDATE0_, messageent0_.MCHANNEL as MCHANNEL0_, messageent0_.MEMAIL as MEMAIL0_, messageent0_.MTITLE as MTITLE0_, messageent0_.MCONTENT as MCONTENT0_, messageent0_.MREPLY as MREPLY0_, messageent0_.MSTATUS as MSTATUS0_ from MESSAGE messageent0_ where messageent0_.MCHANNEL=? and (messageent0_.MREPLY is null) and substr(messageent0_.MSTATUS, 1, 1)= '0 ' and substr(messageent0_.MSTATUS, 2, 1)= '0 ' ) where rownum <= ? for update of messageent0_.mid nowait
17:20:57,515 WARN [
JDBCExceptionReporter] SQL Error: 904, SQLState: 42000
17:20:57,515 ERROR [JDBCExceptionReporter] ORA-00904: "MESSAGEENT0_ ". "MID ": 无效的标识符
我把分页的两句
quMessage.setFirstResult(beginNumber);
quMessage.setMaxResults(numberOfEachPage);
去掉就好了,难道hibernate分页就不能加锁了?
请高人指点。
这是MessageEntity
public class MessageEntity implements Serializable {
private static final long serialVersionUID = -9876321L;
private String mid;
private Calendar messageDate;
private String messageChannel;
private String messageEmail;
private String messageTitle;
private String messageContent;
private String messageReply;
private String messageStatus;
public MessageEntity() {
}
private void readObject(ObjectInputStream ois) throws
IOException,
ClassNotFoundException {
ois.defaultReadObject();
}
private void writeObject(ObjectOutputStream oos) throws IOException {
oos.defaultWriteObject();
}
public void setMid(String mid) {
this.mid = mid;
}
public void setMessageDate(Calendar messageDate) {
this.messageDate = messageDate;
}
public void setMessageChannel(String messageChannel) {
this.messageChannel = messageChannel;
}
public void setMessageEmail(String messageEmail) {
this.m