-->
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.  [ 6 posts ] 
Author Message
 Post subject: Deleteing all records from table
PostPosted: Mon Jul 18, 2005 5:00 am 
Newbie

Joined: Thu Jul 07, 2005 12:21 pm
Posts: 6
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version: 2.1.7


Mapping:

<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE hibernate-mapping
PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">

<hibernate-mapping package="com.scientia.busdir.beans">
<!--<class name="BDDescriptionImpl" table="business_directory_description">
<id name="Id" type="int" column="ID">
<generator class="assigned"/>
</id>


<property name="company_name" column="company_name" type="string" length="50"/>
<property name="address1" column="address1" type="string" length="150"/>
<property name="address2" column="address2" type="string" length="150"/>
<property name="address3" column="address3" type="string" length="150"/>
<property name="town" column="town" type="string" length="50"/>
<property name="county" column="county" type="string" length="50"/>
<property name="postcode" column="postcode" type="string" length="10"/>
<property name="web" column="web" type="string" length="150"/>
<property name="telephone" column="telephone" type="string" length="15"/>
<property name="sic_primary_description" column="sic_primary_description" type="string" length="255"/>
<property name="secondary_description" column="secondary_description" type="string" length="255"/>
<property name="sic_tertiary_description" column="sic_tertiary_description" type="string" length="255"/>
<property name="thomson_description" column="thomson_description" type="string" length="255"/>

<property name="postsect" column="postsect" type="string" length="10"/>
<property name="postdist" column="postdist" type="string" length="5"/>
<property name="postarea" column="postarea" type="string" length="2"/>


<property name="ward_2004_name" column="ward_2004_name" type="string" length="50"/>
<property name="la_2002_name" column="la_2002_name" type="string" length="50"/>
<property name="CTPS" column="CTPS" type="char"/>
<property name="TPS" column="TPS" type="char"/>
<property name="FPS" column="FPS" type="char"/>
<property name="MPS" column="MPS" type="char"/>
</class>-->


<class name="CodedRecordImpl" table="business_directory_coded">
<id name="Id" type="int" column="ID">
<generator class="assigned"/>
</id>
<property name="company_name" column="company_name" type="string" length="50"/>
<property name="address1" column="address1" type="string" length="150"/>
<property name="address2" column="address2" type="string" length="150"/>
<property name="address3" column="address3" type="string" length="150"/>
<property name="town" column="town" type="string" length="50"/>
<property name="county" column="county" type="string" length="50"/>
<property name="postcode" column="postcode" type="string" length="10"/>
<property name="web" column="web" type="string" length="150"/>
<property name="telephone" column="telephone" type="string" length="15"/>
<property name="postsect" column="postsect" type="string" length="10"/>
<property name="postdist" column="postdist" type="string" length="5"/>
<property name="postarea" column="postarea" type="string" length="2"/>
<property name="la_2002" column="la_2002" type="string" length="50"/>
<property name="CTPS" column="CTPS" type="char"/>
<property name="TPS" column="TPS" type="char"/>
<property name="FPS" column="FPS" type="char"/>
<property name="MPS" column="MPS" type="char"/>
<many-to-one name="primaryDescriptionDetails" class="PrimaryDescriptionImpl" column="sic_primary_code"/>
<many-to-one name="secondaryDescriptionDetails" class="SecondaryDescriptionImpl" column="sic_secondary_code"/>
<many-to-one name="tertiaryDescriptionDetails" class="TertiaryDescriptionImpl" column="sic_tertiary_code"/>
<many-to-one name="thomsonDescriptionDetails" class="ThomsonDescriptionImpl" column="thomson_code"/>
<many-to-one name="ward2004Details" class="Ward2004Impl" column="ward_2004"/>
</class>


<class name="PrimaryDescriptionImpl" table="1992_sic_primary_level1_description" lazy="true">
<id name="primary_code" type="char" column="primary_code">
<generator class="assigned"/>
</id>
<property name="primary_description" column="primary_description" type="string" length="150" />
</class>

<class name="SecondaryDescriptionImpl" table="1992_sic_secondary_description" lazy="true">
<id name="secondary_code" type="string" column="secondary_code">
<generator class="assigned"/>
</id>
<property name="secondary_description" column="secondary_description" type="string" length="150"/>
</class>

<class name="TertiaryDescriptionImpl" table="1992_sic_tertiary_description" lazy="true">
<id name="tertiary_code" type="string" column="tertiary_code">
<generator class="assigned"/>
</id>
<property name="tertiary_description" column="tertiary_description" type="string" length="150"/>
</class>

<class name="ThomsonDescriptionImpl" table="lu_thomson" lazy="true">
<id name="thomson_code" type="string" column="thomson_code">
<generator class="assigned"/>
</id>
<property name="thomson_description" column="thomson_description" type="string" length="150"/>
</class>

<class name="Ward2004Impl" table="lu_ward_2004" lazy="true">
<id name="ward_2004" type="string" column="ward_2004">
<generator class="assigned"/>
</id>
<property name="ward_2004_name" column="ward_2004_name" type="string" length="50"/>
<property name="la_2002" column="la_2002" type="string" length="50"/>
</class>

<query name="codedrecord.checkprimary">from PrimaryDescriptionImpl where primary_code = ?</query>
<query name="codedrecord.checksecondary">from SecondaryDescriptionImpl where secondary_code = ?</query>
<query name="codedrecord.checktertiary">from TertiaryDescriptionImpl where tertiary_code = ?</query>
<query name="codedrecord.checkthomson">from ThomsonDescriptionImpl where thomson_code = ?</query>
<query name="codedrecord.checkward">from Ward2004Impl where ward_2004 = ?</query>
<query name="codedrecord.clear">delete from CodedRecordImpl</query>

<query name="codedrecord.search.companyname">from CodedRecordImpl where company_name like ?</query>
<query name="codedrecord.search.pcode">from CodedRecordImpl where sic_primary_code like ?</query>
<query name="codedrecord.search.ward">from CodedRecordImpl where ward_2004 like ?</query>


<query name="primarydescription.getall">from PrimaryDescriptionImpl order by primary_description</query>

<query name="ward.getall">from Ward2004Impl order by ward_2004_name</query>




</hibernate-mapping>




How do i delete all from a table?

I have tried:

super.getSession().delete("from CodedRecordImpl");

and

super.getSession().createQuery("delete from business_directory_coded");


but neither work. What is the correct approch?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 18, 2005 6:00 am 
Expert
Expert

Joined: Tue Oct 05, 2004 9:45 am
Posts: 263
hi,

i think you haven't got the possibility to do this in hb2 ... in hb3 you can do it ...

In HB2 (i think) you have to do it on your own ... (getting the connection from your hb-session etc.)

HTH
curio


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 18, 2005 10:26 am 
Regular
Regular

Joined: Thu Jul 08, 2004 1:21 pm
Posts: 68
Location: Recife - Pernambuco - Brazil
Are you commiting this operation? The session's delete method must do it correctly, at least, in JavaBB project it works fine. Have you some silent exception? Logger in debug mode?

valeuz...

_________________
Marcos Silva Pereira
http://blastemica.blogspot.com


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 18, 2005 12:49 pm 
Beginner
Beginner

Joined: Tue Apr 05, 2005 4:27 pm
Posts: 40
Location: canada
i do this...

Code:
Session s = super.createSession();
Transaction t = s.beginTransaction();
s.connection().prepareStatement("delete from business_directory_coded").execute();
s.connection().commit();
t.commit();
s.close();


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 18, 2005 1:31 pm 
Newbie

Joined: Tue Apr 19, 2005 4:32 pm
Posts: 14
Try ..
Code:
Session s = super.createSession();
Transaction t = s.beginTransaction();
s.createQuery("delete BusinessDirectoryCoded").executeUpdate();
t.commit();
s.close();

.. where BusinessDirectoryCoded is the class mapped to the table business_directory_coded.

-Rishabh


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 18, 2005 5:04 pm 
Expert
Expert

Joined: Tue Oct 05, 2004 9:45 am
Posts: 263
@skewed
you're sure that this code will work with hibernate 2.1.7? I think this is more for HB 3 ...


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