-->
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.  [ 14 posts ] 
Author Message
 Post subject: session.delete but the data are still in the db
PostPosted: Tue May 03, 2005 9:09 am 
Beginner
Beginner

Joined: Fri Jul 16, 2004 3:21 am
Posts: 40
Hibernate version: 3.0.2

Name and version of the database you are using:DB2 8.2.1 eg 8.1.8

Code between sessionFactory.openSession() and session.close():
Transaction trans = session.beginTransaction();
Seller seller = new Seller();
session.load(seller,new Integer(1024));
session.delete(seller);
trans.commit();
session.flush();

the code runs trough but the data entry with the id 1024 is still in the database.

rgds pfenn


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 03, 2005 9:17 am 
Beginner
Beginner

Joined: Wed Nov 24, 2004 10:54 am
Posts: 48
Is this an iSeries (AS/400)? If so you MUST have journaling turned on in order to do add/update/delete on the Physical file. Could that be the problem?


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 03, 2005 9:24 am 
Beginner
Beginner

Joined: Fri Jul 16, 2004 3:21 am
Posts: 40
No the Database runs on a Windows XP and also the POJO App.

rgds pfenn


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 03, 2005 9:30 am 
Beginner
Beginner

Joined: Wed Nov 24, 2004 10:54 am
Posts: 48
OK, well I think I see a problem. You create a NEW object "Seller" then try to set the ID to 1024. I think Hibernate thinks you just created a NEW record in the database table. You probably have to GET the Seller object using a createQuery or createCriteria. Then, once you have a presistent object, you can delete it from the database.


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 03, 2005 10:02 am 
Beginner
Beginner

Joined: Fri Jul 16, 2004 3:21 am
Posts: 40
hi

Seller seller = (Seller)session.get(Seller.class,new Integer(1026));
session.delete(seller);

and again no error but the tuppel is still in the db :-(

I also try this:
Query query = session.createQuery("select c from Seller as c where c.Zip=:zip");
query.setString("zip","ZIP");
for (Iterator it = query.iterate(); it.hasNext();) {
seller = (Seller)it.next();
System.out.println("Seller: " + seller.getName()+" ID : "+seller.getId() );
session.delete(seller);
}
trans.commit();
session.flush();

with the same result

rgds stefan


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 03, 2005 10:07 am 
Beginner
Beginner

Joined: Wed Nov 24, 2004 10:54 am
Posts: 48
Can we see your mapping documents? Are you using a composite key?


Top
 Profile  
 
 Post subject: hibernate.cfg.xml
PostPosted: Tue May 03, 2005 10:18 am 
Beginner
Beginner

Joined: Fri Jul 16, 2004 3:21 am
Posts: 40
<?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.username">user</property>
<property name="hibernate.connection.password">pass</property>
<property name="hibernate.dialect">org.hibernate.dialect.DB2Dialect</property>
<property name="hibernate.connection.url">jdbc:db2://xxx.xxx.xxx.xxx/DB</property>
<property name="hibernate.connection.driver_class">COM.ibm.db2.jdbc.net.DB2Driver</property>
<property name="show_sql">false</property>

<!-- Mapping files -->
<mapping resource="Seller.hbm.xml"/>
<mapping resource="Lelyuser.hbm.xml"/>
<mapping resource="Usedmachine.hbm.xml"/>
</session-factory>
</hibernate-configuration>


Top
 Profile  
 
 Post subject: Seller.hbm.xml
PostPosted: Tue May 03, 2005 10:19 am 
Beginner
Beginner

Joined: Fri Jul 16, 2004 3:21 am
Posts: 40
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping>
<!--
Auto-generated mapping file from
the hibernate.org cfg2hbm engine
-->
<class
name="com.lely.shop.db.Seller"
table="SELLER"
schema="SCHEMA"
>
<id
name="Id"
type="java.lang.Integer"
>
<column name="ID" length="10" not-null="true" unique="true" sql-type="INTEGER" />
<generator class="native" />
</id>

<property
name="Name"
type="java.lang.String"
>
<column name="NAME" not-null="false" sql-type="VARCHAR" />
</property>

<property
name="Firstname"
type="java.lang.String"
>
<column name="FIRSTNAME" not-null="false" sql-type="VARCHAR" />
</property>

<property
name="Address"
type="java.lang.String"
>
<column name="ADDRESS" not-null="false" sql-type="VARCHAR" />
</property>

<property
name="Zip"
type="java.lang.String"
>
<column name="ZIP" not-null="false" sql-type="VARCHAR" />
</property>

<property
name="City"
type="java.lang.String"
>
<column name="CITY" not-null="false" sql-type="VARCHAR" />
</property>

<property
name="Phone"
type="java.lang.String"
>
<column name="PHONE" not-null="false" sql-type="VARCHAR" />
</property>

<property
name="Email"
type="java.lang.String"
>
<column name="EMAIL" not-null="false" sql-type="VARCHAR" />
</property>

<set
name="SetOfUsedmachine"
>
<key>
<column name="SELLERID" length="10" not-null="false" />
</key>
<one-to-many
class="com.lely.shop.db.Usedmachine"
/>
</set>
</class>
</hibernate-mapping>


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 03, 2005 11:19 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
flush() should be called prior to committing.


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 03, 2005 2:28 pm 
Beginner
Beginner

Joined: Fri Jul 16, 2004 3:21 am
Posts: 40
nearly the same code runs with a postgres 8.0 database.
but don't work with a db2 8.2.1

rgds pfenn


Top
 Profile  
 
 Post subject: the solution
PostPosted: Wed May 04, 2005 3:26 am 
Beginner
Beginner

Joined: Fri Jul 16, 2004 3:21 am
Posts: 40
Hi Steve

you're right, the solution by DB2 is first to flush then do commit. Rather then by a Postgres DB, there a commit is enough.

thanks to all for the assistants
rgds stefan


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 04, 2005 9:35 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
Then I would guess that on the postgres driver you have auto-commit set on the driver; *very* dangerous for production systems. Auto-commit basically says that you have no transactions (every statement is a transaction by itself).


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 04, 2005 10:34 am 
Beginner
Beginner

Joined: Fri Jul 16, 2004 3:21 am
Posts: 40
hi steve

i've i open a JDBC Connection then autocommit is everytime on. So when i start a transaction then i disable autocommit.

so that was my understanding wenn i make:

Code:
Transaction trans = session.beginTransaction();


Hibernate shoud disable autocommit:

Code:
conn.setAutoCommit(false);


or i'm wrong.

rgds stefan


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 04, 2005 1:38 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
That is true of the JDBCTransactionFactory. JTATransactionFactory does not muck with the auto-commit.


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