-->
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.  [ 2 posts ] 
Author Message
 Post subject: PLEASE!!! I'dont make a delete register
PostPosted: Wed Jun 07, 2006 3:39 pm 
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 so much,

===============================================
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 5:18 pm 
Beginner
Beginner

Joined: Sat Jun 03, 2006 6:23 pm
Posts: 28
I think that exception simply means, that there was no "Pessoa" record in the database with the key value of 2, so you couldn't delete it.

You could make sure that there is one by loading it with Session.load() or get() first:

Code:
Pessoa p2 = (Pessoa) session.load(Pessoa.class, Integer.valueOf(2));

If you have proxies enabled, you might need to call Hibernate.initialize(p2) to really load the object.

Now, if that says you do have the object, and you still get the exception, you will need to show us what you actually do in genericSHCDAO.delete besides calling session.delete().

Roland


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