Hibernate não deleta

1 resposta
P

Olá pessoal,
tenho um grande problema com deleção e update na base de dados SQL server 2000, select e insert funcionan perfeitamente. Segue a exeption, as classes e mapeamentos:

exception:

org.hibernate.StaleStateException: Unexpected row count: 0 expected: 1

at org.hibernate.jdbc.NonBatchingBatcher.addToBatch(NonBatchingBatcher.java:27)

at org.hibernate.persister.entity.AbstractEntityPersister.delete(AbstractEntityPersister.java:2291)

at org.hibernate.persister.entity.AbstractEntityPersister.delete(AbstractEntityPersister.java:2440)

at org.hibernate.action.EntityDeleteAction.execute(EntityDeleteAction.java:73)

at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:248)

at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:232)

at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:144)

at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:297)

at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)

at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:985)

at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:333)

at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:106)

at br.com.shc.teste.TestaExclusaoPessoa.main(TestaExclusaoPessoa.java:29)

Exception in thread main

Classe persistente:

ublic class Pessoa implements java.io.Serializable {

// Fields    

/**
 * 
 */
private static final long serialVersionUID = -3911440425965000364L;

private Integer id;

private String cpf;

private String nome;

private String sobrenome;

private String idade;

private Date datoco;

// Constructors

/** default constructor */
public Pessoa() {
}

/** minimal constructor */
public Pessoa(String cpf) {
	this.cpf = cpf;
}

/** full constructor */
public Pessoa(String cpf, String nome, String sobrenome, String idade,
		Date datoco) {
	this.cpf = cpf;
	this.nome = nome;
	this.sobrenome = sobrenome;
	this.idade = idade;
	this.datoco = datoco;
}

// Property accessors
public Integer getId() {
	return this.id;
}

public void setId(Integer id) {
	this.id = id;
}

public String getCpf() {
	return this.cpf;
}

public void setCpf(String cpf) {
	this.cpf = cpf;
}

public String getNome() {
	return this.nome;
}

public void setNome(String nome) {
	this.nome = nome;
}

public String getSobrenome() {
	return this.sobrenome;
}

public void setSobrenome(String sobrenome) {
	this.sobrenome = sobrenome;
}

public String getIdade() {
	return this.idade;
}

public void setIdade(String idade) {
	this.idade = idade;
}

public Date getDatoco() {
	return this.datoco;
}

public void setDatoco(Date datoco) {
	this.datoco = datoco;
}

}

main

public class TestaExclusaoPessoa

{

public static void main(String[] args)

{

Configuration configuration = new Configuration();

SessionFactory sessionFactory = configuration.configure().buildSessionFactory();

org.hibernate.Session session = sessionFactory.openSession();

Transaction transaction = session.beginTransaction();
int id = 1;
	
	Pessoa pessoa = (Pessoa) session.get(Pessoa.class, new Integer(id));
	
	System.out.println("PESSOA: " + pessoa.getNome());

	pessoa.setNome("XXXXXX");
	
	session.delete(pessoa);
	
	transaction.commit();

	session.close();

}

}

1 Resposta

L

Este erro está ocorrendo pq não existe este registro com id = 1 na base.

flw

Criado 5 de julho de 2006
Ultima resposta 5 de jul. de 2006
Respostas 1
Participantes 2