-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 
Author Message
 Post subject: MS SQL Server 2000(sp4) + Java 5 problems
PostPosted: Tue Jul 04, 2006 11:13 am 
Beginner
Beginner

Joined: Sun May 07, 2006 4:41 pm
Posts: 20
Location: São Paulo - BRAZIL
Hy guys,
I'm having problems when delete or update one object, however, select and insert they function without problems. I would like to know if it has some incompatibility trhough MS SQL Server 2000(sp4) and Java 5? I try too all drivers JDBC also MS SQL Server 2005 JDBC driver, but only insert and select they function.

Please help me!


Thank's,

_________________
Paulo Nepomuceno
Java Developer


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 04, 2006 9:06 pm 
Regular
Regular

Joined: Thu May 26, 2005 12:20 am
Posts: 72
Can you post what type of error you are getting? Java stacktrace would be a good start!

d

_________________
_________________
dan

If what I say is helpful, please rate the post as such by clicking 'Y'. I appreciate it.


Top
 Profile  
 
 Post subject: reply
PostPosted: Wed Jul 05, 2006 10:10 am 
Beginner
Beginner

Joined: Sun May 07, 2006 4:41 pm
Posts: 20
Location: São Paulo - BRAZIL
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:24
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"


Persistent class:
===============================================
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();

}

}

_________________
Paulo Nepomuceno
Java Developer


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 05, 2006 11:10 am 
Expert
Expert

Joined: Fri Aug 19, 2005 2:11 pm
Posts: 628
Location: Cincinnati
The problem is right here
Code:
pessoa.setNome("XXXXXX");

session.delete(pessoa);


You are changing an object retrieved from the database and then trying to delete it before persisting it. Hibernate can't tell if that object is even from the database.

You should either create a new object that isn't associated to the session and run a delete on it, or update that object after you setNome("XXXX") and then delete.

as always, you have to catch the unexpected row count error if the object cannot be found.

_________________
Chris

If you were at work doing this voluntarily, imagine what you'd want to see to answer a question.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.