2012-03-26 20 views
1

私は冬眠に新しいです。 これは、多くの一対多の休止を経て、多くの関係マッピング多対を持っている私のマスターvisaInquiry豆マッピングです。今のレコードを削除するために、私はは、HibernateはHQLを削除使用して、関連するテーブルを削除しますか?

Transaction ts=session.beginTransaction(); 
       String hql="delete from VisaInquiry inq where inquiryId="+inqId; 
       Query query=session.createQuery(hql); 
       query.executeUpdate(); 
       ts.commit(); 

このクエリを使用していますしかし、問題はそれだけでそれがあるとして、他のテーブル上のすべてのデータが残っているメインtable.Andからレコードを削除することです。私はすべての関連する外国のテーブルからすべてのレコードを削除したい。助けてください?カスケードで

<id name="inquiryId" column="inquiryId"> 
     <generator class="increment"/> 
    </id>   
    <property name="inquiryDate" type="date" column="inquiryDate"></property> 
    <property name="name" type="string" column="name"></property> 
    <property name="countryPreference" type="string" column="countryPreference"></property> 
    <property name="address" type="string" column="address"></property> 
    <property name="pnumberHome" type="string" column="pnumberHome"></property> 
    <property name="pnumberResi" type="string" column="pnumberResi"></property> 
    <property name="email" type="string" column="email"></property> 
    <property name="dob" type="date" column="dob"></property> 
    <property name="englishAblity" type="string" column="englishAblity"></property> 
    <property name="ieltsScore" type="string" column="ieltsScore"></property> 

    <property name="refusedVisa" type="string" column="refusedVisa"></property> 
    <property name="refusedCountry" type="string" column="refusedCountry"></property> 
    <property name="refusedTypeOfVisa" type="string" column="refusedTypeOfVisa"></property> 

    <property name="relativeAbroad" type="string" column="relativeAbroad"></property> 
    <property name="relativeCountry" type="string" column="relativeCountry"></property> 
    <property name="relativeStatus" type="string" column="relativeStatus"></property> 

    <property name="travellAbroad" type="string" column="travellAbroad"></property> 
    <property name="travleCountry" type="string" column="travleCountry"></property> 
    <property name="travelCountryVisaType" type="string" column="travelCountryVisaType"></property> 

    <property name="prefLevelCourse" type="string" column="prefLevelCourse"></property> 
    <property name="counselBy" type="string" column="counselBy"></property> 
    <property name="comeToKnow" type="string" column="comeToKnow"></property> 

    <property name="counselState" type="string" column="counselState"></property> 
    <property name="remarks" type="string" column="remarks"></property> 

    <set name="eduList" table="visaInquiry_education" cascade="persist" lazy="false"> 
     <key column="inquiryId"></key> 

     <many-to-many class="com.aems.beans.EducationQualification" column="educationId" unique="true"></many-to-many> 
    </set> 


    <set name="expList" table="visaInquiry_Experience" cascade="persist" lazy="false"> 
     <key column="inquiryId"></key> 
     <many-to-many class="com.aems.beans.Experience" column="expId" unique="true"></many-to-many> 
    </set> 

    <set name="childList" table="visaInquiry_Children" cascade="persist" lazy="false"> 
     <key column="inquiryId"></key> 
     <many-to-many class="com.`aems`.beans.Children" column="childId" unique="true"></many-to-many> 
    </set> 

    <many-to-one name="spouce" 
    class="com.aems.beans.Spouce" column="spouceId" cascade="persist" unique="true" lazy="false"/> 

= I挿入時にエラーが出る "持続"。挿入時の とカスケードで=「すべて」全く問題なく、ときに私は削除は、一つだけのテーブルからレコードが削除されません取得します。関連するすべてのテーブルのレコードはそのままです。

+0

私はこれを試み、それは私のために正常に動作します.. int id = Integer.parseInt(inquiryId); \t \t \t \t Visaお問い合わせinq =(VisaInquiry)session.load(VisaInquiry.class、id); \t \t \t \t session.delete(inq); \t \t \t \t session.flush(); –

答えて

0

私はこれを試してみました、それは私のために正常に動作します。.. int型のID = Integer.parseInt(inquiryId)。 VisaInquiry inq =(VisaInquiry)session.load(VisaInquiry.class、id); session.delete(inq); session.flush();

0

HQLクエリを削除(一括削除)カスケードはありません。

JPA仕様(JSR338)によれば、セクション4.10:

削除操作のみが指定されたクラスのエンティティおよびそのサブクラスに適用されます。関連するエンティティ にカスケードしません。

したがって、カスケードで削除する必要がある場合は、Session.deleteを使用してください。 Hibernateは分離されたエンティティの削除をサポートしていることに注意してください。これは普通のJPAでは不可能です。

関連する問題