-->
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.  [ 7 posts ] 
Author Message
 Post subject: Exception whiling delete a register
PostPosted: Wed Jun 07, 2006 9:46 am 
Beginner
Beginner

Joined: Sun May 07, 2006 4:41 pm
Posts: 20
Location: São Paulo - BRAZIL
Hy guys,
Always returns e exception when i try exclude de register....

Ps.: follow the exception, class as configuration files.

Thank's,

===============================================
Exception in thread "main" 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.database.dao.generic2.teste.TesteGenerericDAO.main(TesteGenerericDAO.java:111)
===============================================
public class TesteGenerericDAO
{
@SuppressWarnings("unchecked")
public static void main(String[] args)
{
SessionFactory sessionFactory = SessionManager.createSessionFactory();
Session session = sessionFactory.openSession();

GenericSHCDAO genericSHCDAO = new GenericSHCDAO(Pessoa.class, session);

Transaction transaction = session.beginTransaction();
Pessoa pessoa2 = new Pessoa();
pessoa2.setId(new Integer(2).intValue());

genericSHCDAO.delete(pessoa2);
transaction.commit();
session.close();
}
}

===============================================

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.connection.driver_class">com.microsoft.jdbc.sqlserver.SQLServerDriver</property>
<property name="hibernate.connection.password">paulo123</property>
<property name="hibernate.connection.url">jdbc:microsoft:sqlserver://10.173.100.22;DatabaseName=HIBERNATE;SelectMethod=cursor</property>
<property name="hibernate.connection.username">paulonep</property>
<property name="hibernate.dialect">org.hibernate.dialect.SQLServerDialect</property>

<!-- Use the C3P0 connection pool. -->
<property name="c3p0.min_size">3</property>
<property name="c3p0.max_size">5</property>
<property name="c3p0.timeout">1800</property>

<!-- Disable second-level cache. -->
<property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>
<property name="cache.use_query_cache">false</property>
<property name="cache.use_minimal_puts">false</property>
<property name="max_fetch_depth">3</property>

<!-- Print SQL to stdout. -->
<property name="show_sql">true</property>
<property name="format_sql">true</property>

<!-- Drop and then re-create schema on SessionFactory build, for testing. -->
<!-- <property name="hbm2ddl.auto">create</property> -->

<!-- Bind the getCurrentSession() method to the thread. -->
<property name="current_session_context_class">thread</property>

<!-- Hibernate XML mapping files -->

<mapping resource="br/com/shc/database/pessoa/Pessoa.hbm.xml"/>

</session-factory>
</hibernate-configuration>

===============================================

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated 06/06/2006 14:51:19 by Hibernate Tools 3.1.0.beta5 -->
<hibernate-mapping>
<class name="br.com.shc.database.pessoa.Pessoa" table="PESSOA" schema="dbo" catalog="HIBERNATE">
<id name="id" type="java.lang.Integer">
<column name="ID" />
<generator class="native"></generator>
</id>
<property name="cpf" type="java.lang.String">
<column name="CPF" length="11" />
</property>
<property name="nome" type="java.lang.String">
<column name="NOME" length="20" />
</property>
<property name="sobrenome" type="java.lang.String">
<column name="SOBRENOME" length="20" />
</property>
<property name="idade" type="java.lang.String">
<column name="IDADE" length="3" />
</property>
<property name="datoco" type="java.util.Date">
<column name="DATOCO" length="23" />
</property>
</class>
</hibernate-mapping>


===============================================

_________________
Paulo Nepomuceno
Java Developer


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 07, 2006 3:47 pm 
Regular
Regular

Joined: Thu Sep 22, 2005 1:53 pm
Posts: 88
Location: Rio de Janeiro
Quote:
Exception in thread "main" org.hibernate.StaleStateException:


There are two possibilities:
Thrown when a version number or timestamp check failed, indicating that the Session contained stale data (when using long transactions with versioning).
Also occurs if we try delete or update a row that does not exist.

In your case it seems to be the last

Good Luck

_________________
Don´t forget to rate!


Top
 Profile  
 
 Post subject: example
PostPosted: Wed Jun 07, 2006 3:59 pm 
Beginner
Beginner

Joined: Sun May 07, 2006 4:41 pm
Posts: 20
Location: São Paulo - BRAZIL
make a example please...

Thank you!

_________________
Paulo Nepomuceno
Java Developer


Top
 Profile  
 
 Post subject: Re: example
PostPosted: Wed Jun 07, 2006 4:04 pm 
Regular
Regular

Joined: Thu Sep 22, 2005 1:53 pm
Posts: 88
Location: Rio de Janeiro
paulonep wrote:
make a example please...

Thank you!


Sorry changed my post.. was not exactly correct....
You have to verify that the object exists.... so maybe try to load
it before you delete it....

I imagine you do something like

Code:
   session.delete(<object>)


in the GenericSHCDAO class so do a load on the object first to see
if it exists in teh database.

_________________
Don´t forget to rate!


Top
 Profile  
 
 Post subject: I think
PostPosted: Wed Jun 07, 2006 4:05 pm 
Beginner
Beginner

Joined: Sun May 07, 2006 4:41 pm
Posts: 20
Location: São Paulo - BRAZIL
I think with the transactions with versioning case. Therefore, my class contains it. How i can solve this problem, my eclipse make this atribuete in my bean...

Thank's!

package br.com.shc.database.pessoa;

// default package
// Generated 06/06/2006 14:50:48 by Hibernate Tools 3.1.0.beta5

import java.util.Date;

/**
* Pessoa generated by hbm2java
*/
public class Pessoa implements java.io.Serializable {

// Fields

/**
*
*/
private static final long serialVersionUID = 505268519962350039L;

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;
}

}

_________________
Paulo Nepomuceno
Java Developer


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 07, 2006 4:12 pm 
Regular
Regular

Joined: Mon May 22, 2006 2:30 pm
Posts: 74
It's hard to tell exactly what you are doing without the source code for the GenericSHCDAO class. But you can't delete an object if you didn't save it first. Your code appears to attempt to delete an object right after creating it and giving it an id, without ever saving it first. That's not going to work. It will issue a SQL delete statement to remove an object from the database with a primary key matching the id, but it was never added to the database.


Top
 Profile  
 
 Post subject: The register contains in datadase
PostPosted: Wed Jun 07, 2006 4:25 pm 
Beginner
Beginner

Joined: Sun May 07, 2006 4:41 pm
Posts: 20
Location: São Paulo - BRAZIL
Interface method:
void delete(T entity);


This method conains in GenricDAO.
public void delete(T entity) {
getSession().delete(entity);
}

However, i make this code e return de same exception:

public class TesteGenericDaoGravar
{
@SuppressWarnings("unchecked")
public static void main(String[] args)
{
@SuppressWarnings("unused")
Session session = SessionManager.createSession();
@SuppressWarnings("unused")
Transaction transaction = session.beginTransaction();

/*@SuppressWarnings("unused")
GenericSHCDAO genericDAO = new GenericSHCDAO(Class.class, session);

Contrato contrato = new Contrato();

Contrato contrato = (Contrato) session.load(Contrato.class, 1);

contrato.setDescricao("ALTERADO");

session.saveOrUpdate(contrato);

transaction.commit();
session.flush();
session.close();
}

=============================================

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated 07/06/2006 17:09:30 by Hibernate Tools 3.1.0.beta5 -->
<hibernate-mapping>
<class name="br.com.shc.database.contrato.Contrato" table="CONTRATO" schema="dbo" catalog="HIBERNATE">
<id name="chvcontrato" type="java.lang.Integer">
<column name="CHVCONTRATO" />
<generator class="native"></generator>
</id>
<property name="descricao" type="java.lang.String">
<column name="DESCRICAO" length="30" />
</property>
<property name="valor" type="java.lang.Double">
<column name="VALOR" precision="18" scale="0" />
</property>
<property name="dtass" type="java.util.Date">
<column name="DTASS" length="23" />
</property>
<property name="chvhumano" type="java.lang.Integer">
<column name="CHVHUMANO" />
</property>
<property name="dtoco" type="java.util.Date">
<column name="DTOCO" length="23" />
</property>
<property name="chvstatus" type="java.lang.Integer">
<column name="CHVSTATUS" />
</property>
</class>
</hibernate-mapping>

=================================================
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.connection.driver_class">com.microsoft.jdbc.sqlserver.SQLServerDriver</property>
<property name="hibernate.connection.password">paulo123</property>
<property name="hibernate.connection.url">jdbc:microsoft:sqlserver://10.173.100.22;DatabaseName=HIBERNATE;SelectMethod=cursor</property>
<property name="hibernate.connection.username">paulonep</property>
<property name="hibernate.dialect">org.hibernate.dialect.SQLServerDialect</property>

<!-- Use the C3P0 connection pool. -->
<property name="c3p0.min_size">3</property>
<property name="c3p0.max_size">5</property>
<property name="c3p0.timeout">1800</property>

<!-- Disable second-level cache. -->
<property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>
<property name="cache.use_query_cache">false</property>
<property name="cache.use_minimal_puts">false</property>
<property name="max_fetch_depth">3</property>

<!-- Print SQL to stdout. -->
<property name="show_sql">true</property>
<property name="format_sql">true</property>

<!-- Drop and then re-create schema on SessionFactory build, for testing. -->
<!-- <property name="hbm2ddl.auto">create</property> -->

<!-- Bind the getCurrentSession() method to the thread. -->
<property name="current_session_context_class">thread</property>

<!-- Hibernate XML mapping files -->

<mapping resource="br/com/shc/database/pessoa/Pessoa.hbm.xml"/>
<mapping resource="br/com/shc/database/contrato/Contrato.hbm.xml"/>
<mapping resource="br/com/shc/database/hcontrato/HContrato.hbm.xml"/>

</session-factory>
</hibernate-configuration>

_________________
Paulo Nepomuceno
Java Developer


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 7 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.