-->
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+Spring] handling transient entity in delete proce
PostPosted: Sun Apr 01, 2012 2:48 am 
Newbie

Joined: Tue Mar 27, 2012 6:27 am
Posts: 2
I have exception in my "delete" method but similar "add" method working correct.
Please help me with my problem))
Code:
26.03.2012 21:33:41 org.hibernate.event.internal.DefaultDeleteEventListener deleteTransientEntity
INFO: HHH000114: Handling transient entity in delete processing


Code:
   public void delBlockedProcess(String ip, String nameBlockProcess) throws SQLException{
      Session session = null;   
      
      try{
         BlockedProcess exemBlock = new BlockedProcess();
         exemBlock.setClientIP_id(ip);
         exemBlock.setBlockedName(nameBlockProcess);
         session = factory.openSession();
         session.beginTransaction();
         session.delete(exemBlock);
         session.getTransaction().commit();
      }catch(Exception ex){
         System.out.println("Error in delBlockedNameByIP  " + ex.getMessage());
      }finally{
         if(session != null && session.isOpen()){
            
            session.close();
         }
         
      }
      
   }


Code:
<bean id="propertyConfigurer"  class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">

    <property name="location" value="/WEB-INF/jdbc.properties" />

</bean>
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">

    <property name="driverClassName" value="${jdbc.driverClassName}" />

    <property name="url" value="${jdbc.databaseurl}" />

    <property name="username" value="${jdbc.username}" />

    <property name="password" value="${jdbc.password}" />

</bean>
<bean id="mySessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
                 
                  <property name="mappingResources">
                        <list>                           
                            <value>springapp/hibernate_logic/ClientIP.hbm.xml</value>
                      <value>springapp/hibernate_logic/StartProcess.hbm.xml</value>
                      <value>springapp/hibernate_logic/BlockedProcess.hbm.xml</value>                 
                        </list>
                    </property>
                   <property name="hibernateProperties">
                   <props>                   
                    <prop key="hibernate.dialect">${jdbc.dialect}</prop>
                    <prop key="hibernate.show_sql">true</prop>
                   </props>
                   </property>
                    <property name="dataSource">
                        <ref bean="dataSource"/>
                    </property>
                     
                </bean>
             


Top
 Profile  
 
 Post subject: Re: [Hibernate+Spring] handling transient entity in delete proce
PostPosted: Sun Apr 01, 2012 9:27 am 
Newbie

Joined: Thu Apr 21, 2011 8:59 am
Posts: 14
Hi,

When you do a new BlockedProcess() and an add(), it adds that new object into the database.
However, when you are doing a new() and then followed by a delete(), you are trying to delete an object that is not even present in the database. so, that should be why you are facing the issue.

what should you try is,
opensession()
beginTransaction()
find() the required entity from the database
delete() that entity fetched from database
commit.

This should work.

_________________
Lokesh, C
( SCBCD 5, CCENT, SCJP 5 )


Top
 Profile  
 
 Post subject: Re: [Hibernate+Spring] handling transient entity in delete proce
PostPosted: Mon Apr 02, 2012 1:02 pm 
Newbie

Joined: Tue Mar 27, 2012 6:27 am
Posts: 2
Thanks


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.