-->
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.  [ 3 posts ] 
Author Message
 Post subject: Hibernate seems to delete a record successfully but ........
PostPosted: Sun Feb 03, 2008 7:27 am 
Newbie

Joined: Sun Jan 27, 2008 11:45 pm
Posts: 3
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

[b]Hibernate version: 3[/b]

[b]Mapping documents: <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"hibernate-mapping-3.0.dtd" >

<hibernate-mapping package="com.oxman.entities">
<class name="Subject" table="oxm_subjects">
<id name="subjectID" column="subject_id" type="int" unsaved-value="null">
<generator class="native"/>
</id>

<property name="subjectName" column="subject_name" type="string" length="255"/>
<property name="subjectDescription" column="subject_description" type="string" length="255"/>
<property name="isSubjectEnabled" column="subject_enabled" type="boolean"/>
<set name="termSet" table="oxm_termsubj" cascade="save-update" lazy="false">
<key column="termsubj_subject_id"/>
<many-to-many class="Term" column="termsubj_term_id"/>
</set>
<property name="subjectUserID" column="subject_user_id" type="int"/>
</class>
</hibernate-mapping>

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping
PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"hibernate-mapping-3.0.dtd" >

<hibernate-mapping package="com.oxman.entities">
<class name="Term" table="oxm_terms">
<id name="termID" column="term_id" type="int" unsaved-value="null">
<generator class="native"/>
</id>
<property name="termName" column="term_name" type="string" length="255"/>
<property name="termDescription" column="term_description" type="string" length="255"/>
<property name="termBeginDate" column="term_begin_time" type="date"/>
<property name="termEndDate" column="term_end_time" type="date"/>

<set name="subjectSet" table="oxm_termsubj" cascade="save-update" inverse="true">
<key column="termsubj_term_id"/>
<many-to-many class="Subject" column="termsubj_subject_id"/>
</set>
</class>
</hibernate-mapping>

[/b]

[b]Code between sessionFactory.openSession() and session.close():
try{
Query query = session.createQuery("from Subject s where s.subjectName = :name");
query.setParameter("name", subjectName);
Subject subject = (Subject)query.list().get(0);

session.delete(subject);

return "deleting subject.";
}catch(Exception exception){
exception.printStackTrace();
return "somethingWrong";
}finally{
if(session != null){
try{
HibernateFactory.close(session);
HibernateFactory.closeFactory();
}catch(HibernateException ignore){
//ignore
}
}
}[/b]

[b]Full stack trace of any exception that occurs:
no exception occured but session.delete(subject); ran with no problem.
but problem is the record doesn't get deleted
[/b]

[b]Name and version of the database you are using: MySQL Server 5.0[/b]

[b]The generated SQL (show_sql=true):
Hibernate: select term0_.term_id as term1_0_, term0_.term_name as term2_0_, term0_.term_description as term3_0_, term0_.term_begin_time as term4_0_, term0_.term_end_time as term5_0_ from oxm_terms term0_
Hibernate: select term0_.term_id as term1_5_, term0_.term_name as term2_5_, term0_.term_description as term3_5_, term0_.term_begin_time as term4_5_, term0_.term_end_time as term5_5_ from oxm_terms term0_ where term0_.term_name like ?
Hibernate: select subject0_.subject_id as subject1_12_, subject0_.subject_name as subject2_12_, subject0_.subject_description as subject3_12_, subject0_.subject_enabled as subject4_12_, subject0_.subject_user_id as subject5_12_ from oxm_subjects subject0_ where subject0_.subject_id=2
Hibernate: select termset0_.termsubj_subject_id as termsubj2_1_, termset0_.termsubj_term_id as termsubj1_1_, term1_.term_id as term1_10_0_, term1_.term_name as term2_10_0_, term1_.term_description as term3_10_0_, term1_.term_begin_time as term4_10_0_, term1_.term_end_time as term5_10_0_ from oxm_termsubj termset0_ left outer join oxm_terms term1_ on termset0_.termsubj_term_id=term1_.term_id where termset0_.termsubj_subject_id=?
Hibernate: select subject0_.subject_id as subject1_17_, subject0_.subject_name as subject2_17_, subject0_.subject_description as subject3_17_, subject0_.subject_enabled as subject4_17_, subject0_.subject_user_id as subject5_17_ from oxm_subjects subject0_ where subject0_.subject_id=6
Hibernate: select termset0_.termsubj_subject_id as termsubj2_1_, termset0_.termsubj_term_id as termsubj1_1_, term1_.term_id as term1_15_0_, term1_.term_name as term2_15_0_, term1_.term_description as term3_15_0_, term1_.term_begin_time as term4_15_0_, term1_.term_end_time as term5_15_0_ from oxm_termsubj termset0_ left outer join oxm_terms term1_ on termset0_.termsubj_term_id=term1_.term_id where termset0_.termsubj_subject_id=?
Hibernate: select subject0_.subject_id as subject1_22_, subject0_.subject_name as subject2_22_, subject0_.subject_description as subject3_22_, subject0_.subject_enabled as subject4_22_, subject0_.subject_user_id as subject5_22_ from oxm_subjects subject0_ where subject0_.subject_id=9
Hibernate: select termset0_.termsubj_subject_id as termsubj2_1_, termset0_.termsubj_term_id as termsubj1_1_, term1_.term_id as term1_20_0_, term1_.term_name as term2_20_0_, term1_.term_description as term3_20_0_, term1_.term_begin_time as term4_20_0_, term1_.term_end_time as term5_20_0_ from oxm_termsubj termset0_ left outer join oxm_terms term1_ on termset0_.termsubj_term_id=term1_.term_id where termset0_.termsubj_subject_id=?
Hibernate: select term0_.term_id as term1_25_, term0_.term_name as term2_25_, term0_.term_description as term3_25_, term0_.term_begin_time as term4_25_, term0_.term_end_time as term5_25_ from oxm_terms term0_
Hibernate: select subject0_.subject_id as subject1_32_, subject0_.subject_name as subject2_32_, subject0_.subject_description as subject3_32_, subject0_.subject_enabled as subject4_32_, subject0_.subject_user_id as subject5_32_ from oxm_subjects subject0_ where subject0_.subject_name=?
Hibernate: select termset0_.termsubj_subject_id as termsubj2_1_, termset0_.termsubj_term_id as termsubj1_1_, term1_.term_id as term1_30_0_, term1_.term_name as term2_30_0_, term1_.term_description as term3_30_0_, term1_.term_begin_time as term4_30_0_, term1_.term_end_time as term5_30_0_ from oxm_termsubj termset0_ left outer join oxm_terms term1_ on termset0_.termsubj_term_id=term1_.term_id where termset0_.termsubj_subject_id=?
[/b]

[b]Debug level Hibernate log excerpt:[/b]


Problems with Session and transaction handling?

I have a many-to-many association between subject and term(semester).
When I tried to delete a subject. this command session.delete(subject); ran fine but the record doesn't get deleted.

if anyone knows what the cause of the problem is please let me know


thank you so much

sura

Read this: http://hibernate.org/42.html


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 04, 2008 5:23 pm 
Newbie

Joined: Tue Jan 29, 2008 2:30 am
Posts: 7
Hi,

I'm not sure if you have solved this problem, but it looks like the session is not being flushed.

I'm not sure whether the Util class you are using to close the session also flushes it, but you will probably need to either explicitly flush it or modify configuration to ensure that the session is flushed.

Cheers

Ryan


Top
 Profile  
 
 Post subject: thank you so much ryan.lea
PostPosted: Mon Feb 04, 2008 10:37 pm 
Newbie

Joined: Sun Jan 27, 2008 11:45 pm
Posts: 3
thank you so much ryan.lea

Yes I have solved the problem.
It is my mistake.
I need to to run transaction.commit(); in order to delete the object

but thanks anyway for the suggestion

Cheers,

Sura


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