Bom dia,
são 00:15 e realmente eu não sai mais o que fazer...
Estou com um problema em uma aplicação que utiliza hibernate 3...O erro que ocorre é o seguinte...
Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect): [com.gvt.bpm.common.bo.BpmContato#a1b7f373-444a-11df-aaf2-00007f000001]
Segue o mapeamento do arquivo que está dando erro:
<class name="com.gvt.bpm.common.bo.BpmContato"
table="bpm_contato"
dynamic-update="true"
dynamic-insert="true"
select-before-update="true"
optimistic-lock="version"
lazy="false">
<id name="objectID" column="objectid">
<generator class="assigned"/>
</id>
<timestamp column="timestamp" name="timestamp" source="db"/>
<property name="nome" column="nome"/>
<property name="telefoneResidencial" column="telefoneresidencial"/>
<property name="telefoneCelular" column="telefonecelular"/>
<property name="telefoneComercial" column="telefonecomercial"/>
<property name="contatoPrincipal" column="contatoprincipal"/>
<property name="objectIdCustomerOrder" column="objectid_customerorder"/>
</class>
o código da classe
package com.gvt.bpm.common.bo;
import java.io.Serializable;
import java.sql.Timestamp;
public class BpmContato implements Serializable {
private static final long serialVersionUID = 933883483L;
/*
* local variables to maintain the new, modified and deleted state
*/
private boolean _modified = false;
private boolean _deleted = false;
private boolean _new = true;
private String telefoneResidencial="";
private boolean telefoneResidencialModified = false;
private String nome="";
private boolean nomeModified = false;
private String objectID="";
private boolean objectIDModified = false;
private Boolean contatoPrincipal= new Boolean(false);
private boolean contatoPrincipalModified = false;
private String objectIdCustomerOrder="";
private boolean objectIdCustomerOrderModified = false;
private String telefoneCelular="";
private boolean telefoneCelularModified = false;
private String telefoneComercial="";
private boolean telefoneComercialModified = false;
private Timestamp timestamp= Timestamp.valueOf("2008-03-05 11:00:15.44");
private boolean timestampModified = false;
private String objectIdCustomerorder="";
private boolean objectIdCustomerorderModified = false;
public BpmContato(){
}
public BpmContato(String _objectID){
objectID = _objectID;
}
public BpmContato(String _telefoneResidencial,String _nome,String _objectID,Boolean _contatoPrincipal,String _objectIdCustomerOrder,String _telefoneCelular,String _telefoneComercial,Timestamp _timestamp,String _objectIdCustomerorder){
telefoneResidencial = _telefoneResidencial;
nome = _nome;
objectID = _objectID;
contatoPrincipal = _contatoPrincipal;
objectIdCustomerOrder = _objectIdCustomerOrder;
telefoneCelular = _telefoneCelular;
telefoneComercial = _telefoneComercial;
timestamp = _timestamp;
objectIdCustomerorder = _objectIdCustomerorder;
}
public String getTelefoneResidencial(){
return telefoneResidencial;
}
public boolean checkIsTelefoneResidencialModified(){
return telefoneResidencialModified;
}
public void setTelefoneResidencial(String _telefoneResidencial){
if((this.telefoneResidencial == null) && (_telefoneResidencial == null)){
return;
}
if(!((this.telefoneResidencial != null) && (this.telefoneResidencial.equals(_telefoneResidencial)))){
this.telefoneResidencial = _telefoneResidencial;
this.telefoneResidencialModified = true;
_modified = true;
}
else if(!((_telefoneResidencial != null) && (_telefoneResidencial.equals(this.telefoneResidencial)))){
this.telefoneResidencial = _telefoneResidencial;
this.telefoneResidencialModified = true;
_modified = true;
}
}
public String getNome(){
return nome;
}
public boolean checkIsNomeModified(){
return nomeModified;
}
public void setNome(String _nome){
if((this.nome == null) && (_nome == null)){
return;
}
if(!((this.nome != null) && (this.nome.equals(_nome)))){
this.nome = _nome;
this.nomeModified = true;
_modified = true;
}
else if(!((_nome != null) && (_nome.equals(this.nome)))){
this.nome = _nome;
this.nomeModified = true;
_modified = true;
}
}
public String getObjectID(){
return objectID;
}
public boolean checkIsObjectIDModified(){
return objectIDModified;
}
public void setObjectID(String _objectID){
if((this.objectID == null) && (_objectID == null)){
return;
}
if(!((this.objectID != null) && (this.objectID.equals(_objectID)))){
this.objectID = _objectID;
this.objectIDModified = true;
_modified = true;
}
else if(!((_objectID != null) && (_objectID.equals(this.objectID)))){
this.objectID = _objectID;
this.objectIDModified = true;
_modified = true;
}
}
public Boolean getContatoPrincipal(){
return contatoPrincipal;
}
public boolean checkIsContatoPrincipalModified(){
return contatoPrincipalModified;
}
public void setContatoPrincipal(Boolean _contatoPrincipal){
if((this.contatoPrincipal == null) && (_contatoPrincipal == null)){
return;
}
if(!((this.contatoPrincipal != null) && (this.contatoPrincipal.equals(_contatoPrincipal)))){
this.contatoPrincipal = _contatoPrincipal;
this.contatoPrincipalModified = true;
_modified = true;
}
else if(!((_contatoPrincipal != null) && (_contatoPrincipal.equals(this.contatoPrincipal)))){
this.contatoPrincipal = _contatoPrincipal;
this.contatoPrincipalModified = true;
_modified = true;
}
}
public String getObjectIdCustomerOrder(){
return objectIdCustomerOrder;
}
public boolean checkIsObjectIdCustomerOrderModified(){
return objectIdCustomerOrderModified;
}
public void setObjectIdCustomerOrder(String _objectIdCustomerOrder){
if((this.objectIdCustomerOrder == null) && (_objectIdCustomerOrder == null)){
return;
}
if(!((this.objectIdCustomerOrder != null) && (this.objectIdCustomerOrder.equals(_objectIdCustomerOrder)))){
this.objectIdCustomerOrder = _objectIdCustomerOrder;
this.objectIdCustomerOrderModified = true;
_modified = true;
}
else if(!((_objectIdCustomerOrder != null) && (_objectIdCustomerOrder.equals(this.objectIdCustomerOrder)))){
this.objectIdCustomerOrder = _objectIdCustomerOrder;
this.objectIdCustomerOrderModified = true;
_modified = true;
}
}
public String getTelefoneCelular(){
return telefoneCelular;
}
public boolean checkIsTelefoneCelularModified(){
return telefoneCelularModified;
}
public void setTelefoneCelular(String _telefoneCelular){
if((this.telefoneCelular == null) && (_telefoneCelular == null)){
return;
}
if(!((this.telefoneCelular != null) && (this.telefoneCelular.equals(_telefoneCelular)))){
this.telefoneCelular = _telefoneCelular;
this.telefoneCelularModified = true;
_modified = true;
}
else if(!((_telefoneCelular != null) && (_telefoneCelular.equals(this.telefoneCelular)))){
this.telefoneCelular = _telefoneCelular;
this.telefoneCelularModified = true;
_modified = true;
}
}
public String getTelefoneComercial(){
return telefoneComercial;
}
public boolean checkIsTelefoneComercialModified(){
return telefoneComercialModified;
}
public void setTelefoneComercial(String _telefoneComercial){
if((this.telefoneComercial == null) && (_telefoneComercial == null)){
return;
}
if(!((this.telefoneComercial != null) && (this.telefoneComercial.equals(_telefoneComercial)))){
this.telefoneComercial = _telefoneComercial;
this.telefoneComercialModified = true;
_modified = true;
}
else if(!((_telefoneComercial != null) && (_telefoneComercial.equals(this.telefoneComercial)))){
this.telefoneComercial = _telefoneComercial;
this.telefoneComercialModified = true;
_modified = true;
}
}
public Timestamp getTimestamp(){
return timestamp;
}
public boolean checkIsTimestampModified(){
return timestampModified;
}
public void setTimestamp(Timestamp _timestamp){
if((this.timestamp == null) && (_timestamp == null)){
return;
}
if(!((this.timestamp != null) && (this.timestamp.equals(_timestamp)))){
this.timestamp = _timestamp;
this.timestampModified = true;
_modified = true;
}
else if(!((_timestamp != null) && (_timestamp.equals(this.timestamp)))){
this.timestamp = _timestamp;
this.timestampModified = true;
_modified = true;
}
}
public String getObjectIdCustomerorder(){
return objectIdCustomerorder;
}
public boolean checkIsObjectIdCustomerorderModified(){
return objectIdCustomerorderModified;
}
public void setObjectIdCustomerorder(String _objectIdCustomerorder){
if((this.objectIdCustomerorder == null) && (_objectIdCustomerorder == null)){
return;
}
if(!((this.objectIdCustomerorder != null) && (this.objectIdCustomerorder.equals(_objectIdCustomerorder)))){
this.objectIdCustomerorder = _objectIdCustomerorder;
this.objectIdCustomerorderModified = true;
_modified = true;
}
else if(!((_objectIdCustomerorder != null) && (_objectIdCustomerorder.equals(this.objectIdCustomerorder)))){
this.objectIdCustomerorder = _objectIdCustomerorder;
this.objectIdCustomerorderModified = true;
_modified = true;
}
}
/*
* equals() method of the business object
*/
public boolean equals(Object obj){
if(!( obj instanceof BpmContato))
return false;
BpmContato other = (BpmContato)obj;
if(other == null) return false;
if(this == other) return true;
return true
&& ((objectID==null && other.getObjectID() == null) ||
((objectID!=null) && (objectID.equals(other.getObjectID())))) ;
}
/*
* hashCode() method of the business object
*/
public int hashCode(){
int _hashCode = 0;
if(telefoneResidencial!= null){
_hashCode += 29*_hashCode + (telefoneResidencial.hashCode());
}
if(nome!= null){
_hashCode += 29*_hashCode + (nome.hashCode());
}
if(objectID!= null){
_hashCode += 29*_hashCode + (objectID.hashCode());
}
if(contatoPrincipal!= null){
_hashCode += 29*_hashCode + (contatoPrincipal.hashCode());
}
if(objectIdCustomerOrder!= null){
_hashCode += 29*_hashCode + (objectIdCustomerOrder.hashCode());
}
if(telefoneCelular!= null){
_hashCode += 29*_hashCode + (telefoneCelular.hashCode());
}
if(telefoneComercial!= null){
_hashCode += 29*_hashCode + (telefoneComercial.hashCode());
}
if(timestamp!= null){
_hashCode += 29*_hashCode + (timestamp.hashCode());
}
if(objectIdCustomerorder!= null){
_hashCode += 29*_hashCode + (objectIdCustomerorder.hashCode());
}
return _hashCode;
}
/*
* toString() method of the business object
*/
public String toString(){
StringBuilder pw = new StringBuilder(200);
pw.append("com.gvt.bpm.common.bo.BpmContato ::");
pw.append("telefoneResidencial=" + telefoneResidencial+ "\n");
pw.append("nome=" + nome+ "\n");
pw.append("objectID=" + objectID+ "\n");
pw.append("contatoPrincipal=" + contatoPrincipal+ "\n");
pw.append("objectIdCustomerOrder=" + objectIdCustomerOrder+ "\n");
pw.append("telefoneCelular=" + telefoneCelular+ "\n");
pw.append("telefoneComercial=" + telefoneComercial+ "\n");
pw.append("timestamp=" + timestamp+ "\n");
pw.append("objectIdCustomerorder=" + objectIdCustomerorder+ "\n");
return pw.toString();
}
/*
* check the _modified state of the business object
*/
public boolean checkIsModified(){
return _modified;
}
/*
* check the _deleted state of the business object
*/
public boolean checkIsDeleted(){
return _deleted;
}
/*
* check the _new state of the business object
*/
public boolean checkIsNew(){
return _new;
}
/*
* marks the object to be deleted
*/
public void markDeleted() {
_deleted = true;
}
/*
* marks the object to be new
*/
public void markNew() {
_new = true;
}
/*
* marks the object to be new
*/
public void markModified() {
_modified = true;
}
/*
* resets the flags of all variables to false
*/
public void resetFlags() {
_modified = false;
_new = false;
_deleted = false;
telefoneResidencialModified= false;
nomeModified= false;
objectIDModified= false;
contatoPrincipalModified= false;
objectIdCustomerOrderModified= false;
telefoneCelularModified= false;
telefoneComercialModified= false;
timestampModified= false;
objectIdCustomerorderModified= false;
}
}
todos os campos estão mapeados corretamente no banco...O erro ocorre quando eu chamdo o método saveOrUpdate...
HibernateDAOUtil hiber = HibernateDAOUtil.getInstance();
Session ses = hiber.createSession();
Transaction tx = null;
try {
tx = ses.beginTransaction();
/*if(customerOrder.getEnderecoDesconexao() != null && customerOrder.getEnderecoDesconexao().checkIsModified()) {
ses.saveOrUpdate(customerOrder.getEnderecoDesconexao());
//Force this session to flush. Must be called at the end of a unit of work,
//before commiting the transaction and closing the session
ses.flush();
}*/
/*if(customerOrder.getEnderecoInstalacao() != null && customerOrder.getEnderecoInstalacao().checkIsModified()) {
ses.saveOrUpdate(customerOrder.getEnderecoInstalacao());
ses.flush();
}*/
if(customerOrder.getCliente() != null && customerOrder.getCliente().checkIsModified()) {
ses.saveOrUpdate(customerOrder.getCliente());
ses.flush();
}
if(customerOrder != null && customerOrder.getContatos() != null){
for(BpmContato contato : customerOrder.getContatos()){
if(contato.checkIsModified()){
//o codigo desse cara está um pouco abaixo
BpmContatoDAO.updateContato(ses, contato, logIdentity);
}
}
ses.flush();
}
public static void updateContato(Session ses, BpmContato contato, String logIdentity) {
ses.saveOrUpdate(contato);
ses.flush();
log.debug(logIdentity + "UPDATED CONTATO: " + contato.getObjectID());
}
Se alguém já passou por isso, por td...me ajude...
Muito Obrigado,
Leonardo De Bona