-->
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: Update and delete not working
PostPosted: Mon Sep 15, 2008 3:09 am 
Newbie

Joined: Mon Sep 15, 2008 12:29 am
Posts: 4
Hi everyone, I have this problem when trying to make an update or a delete.
I use Spring to get along with the Sessions stuff, autocommit etc..


Hibernate version:
3.3.1
Mapping documents:

Code:
@Entity
@Table(name = "LIBRARYITEM")
@SuppressWarnings("serial")
public class Libraryitem implements Serializable {

//all the attributes...
@Basic
   @Id
   @GeneratedValue
   @Column(name = "ITEMRECNUMBER")
      public Integer getItemrecnumber() {
      return itemrecnumber;
   }
//Rest of getters and setters...



Code between sessionFactory.openSession() and session.close():

Code:
//
public abstract class AbstractHibernateDAO<T, ID extends Serializable> extends HibernateDaoSupport implements GenericDAO<T, ID> {
//stuff..

public void update(T entity) {
      getSession().update(entity);
   }
//or
   public void saveOrUpdate(T entity) {
      getSession().saveOrUpdate(entity);
   }
//or   
   public void delete(T entity) {
      getSession().delete(entity);
   }



Name and version of the database you are using:
HSQL
The generated SQL (show_sql=true):

When inserting.. I do got to see the SQL also when doing selects
Code:
20:59:27,564 DEBUG SQL:401 - /* insert biblioteca.pojo.Libraryitem */ insert into LIBRARYITEM (ITEMRECNUMBER, ITEMAUTHOR, ITEMBRIEFDESC, ITEMCALLNUMBER, ITEMCATEGORY, ITEMISBN, ITEMKEYWORD, ITEMLANGUAGE, ITEMLENGTH, ITEMMEDIATYPE, ITEMPUBLISHERNAME, ITEMSUBJECT, ITEMTITLE, ITEMTOTAVAILABLE, ITEMTOTBORROW, ITEMTOTQUANTITY, ITEMTOTRESERVE, ITEMYEAR) values (null, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
Hibernate: /* insert biblioteca.pojo.Libraryitem */ insert into LIBRARYITEM (ITEMRECNUMBER, ITEMAUTHOR, ITEMBRIEFDESC, ITEMCALLNUMBER, ITEMCATEGORY, ITEMISBN, ITEMKEYWORD, ITEMLANGUAGE, ITEMLENGTH, ITEMMEDIATYPE, ITEMPUBLISHERNAME, ITEMSUBJECT, ITEMTITLE, ITEMTOTAVAILABLE, ITEMTOTBORROW, ITEMTOTQUANTITY, ITEMTOTRESERVE, ITEMYEAR) values (null, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)



But any time I do an update or delete.. it stays there..
Debug level Hibernate log excerpt:

Code:
21:03:26,837 DEBUG SessionImpl:220 - opened session at timestamp: 12214442068
21:03:26,838 DEBUG IdentifierValue:104 - id unsaved-value: null
21:03:26,839 DEBUG AbstractSaveEventListener:523 - detached instance of: biblioteca.pojo.Libraryitem
21:03:26,840 DEBUG DefaultSaveOrUpdateEventListener:205 - updating detached instance
21:03:26,840 DEBUG DefaultSaveOrUpdateEventListener:272 - updating [biblioteca.pojo.Libraryitem#1]
21:03:26,847 DEBUG DefaultSaveOrUpdateEventListener:323 - updating [biblioteca.pojo.Libraryitem#1]


The update or delete just never gets executed
What could this be??

Thank you so much for your time

bye[/code]


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 15, 2008 4:55 am 
Newbie

Joined: Fri Sep 09, 2005 11:09 am
Posts: 7
Location: Clermont-Ferrand
Hi,
can you post your spring config?

_________________
Mickael Gervais
Agaetis


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 15, 2008 12:38 pm 
Newbie

Joined: Mon Sep 15, 2008 12:29 am
Posts: 4
mgervais wrote:
Hi,
can you post your spring config?


Hi, thanks for the quick response, heres my conf from the applicationContext.xml
Code:

<bean id=" dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
            <property name="driverClassName" value="org.hsqldb.jdbcDriver"/>
            <property name="url" value="jdbc:hsqldb:file:/home/phasnox/espol/DAW/hsql/biblioteca"/>
            <property name="username" value="sa"/>
            <property name="password" value=""/>
            <property name="maxActive" value="100"/>
            <property name="maxIdle" value="30"/>
            <property name="maxWait" value="1000"/>
            <property name="defaultAutoCommit" value="true"/>
            <property name="removeAbandoned" value="true"/>
            <property name="removeAbandonedTimeout" value="60"/>
        </bean>
   <!-- Hibernate SessionFactory -->
   <bean id="sessionFactory"
      class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
      <property name="dataSource" ref="dataSource" />
      <property name="annotatedClasses">
         <list>
            <value>biblioteca.pojo.Borrowrec</value>
            <value>biblioteca.pojo.Libraryitem</value>
            <value>biblioteca.pojo.Penaltyrec</value>
            <value>biblioteca.pojo.Reserverec</value>
            <value>biblioteca.pojo.User</value>
         </list>
      </property>
      <property name="hibernateProperties">
                    <props>
                        <prop key="hibernate.dialect">org.hibernate.dialect.HSQLDialect</prop>
                        <prop key="hibernate.query.substitutions">Y</prop>
                        <prop key="hibernate.show_sql">true</prop>
                        <prop key="hibernate.use_sql_comments">true</prop>
                        <!-- Turn batching off for better error messages under PostgreSQL
                                <prop key="hibernate.jdbc.batch_size">0</prop> -->
                    </props>
      </property>
   </bean>

   
       
   <!-- Transaction manager for a single Hibernate SessionFactory (alternative to JTA) -->
   <bean id="transactionManager"
      class="org.springframework.orm.hibernate3.HibernateTransactionManager">
      <property name="sessionFactory" ref="sessionFactory" />
   </bean>

        <bean id="libraryitemDAO" class="biblioteca.hibernate.LibraryitemHibernateDAO">
      <property name="sessionFactory" ref="sessionFactory" />
   </bean>



and from the dispatcher-servlet.xml
Code:

<context:component-scan base-package="biblioteca.web"/>
    <bean class="org.springframework.web.servlet.handler.SimpleMappingExceptionResolver">
            <property name="exceptionMappings">
                    <props>
                            <prop key="org.springframework.dao.DataAccessException">dataAccessFailure</prop>
                            <prop key="org.springframework.transaction.TransactionException">dataAccessFailure</prop>
                    </props>
            </property>
    </bean>

       
    <bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource">
        <property name="basename" value="messages"/>
    </bean>
   
    <bean id="viewResolver"
          class="org.springframework.web.servlet.view.InternalResourceViewResolver"
          p:prefix="/WEB-INF/jsp/"
          p:suffix=".jsp" />
   
</beans>


Its rather odd.. The inserts are working fine..

Thank you so much for your time.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 15, 2008 1:39 pm 
Regular
Regular

Joined: Mon Apr 19, 2004 6:54 pm
Posts: 79
Looks like you have problem with your id, it is always null.

Christophe


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 15, 2008 6:00 pm 
Newbie

Joined: Mon Sep 15, 2008 12:29 am
Posts: 4
croudet wrote:
Looks like you have problem with your id, it is always null.

Christophe


Hi. yes the unsaved-value seems to be setting to null. But the actual id in the entity when I do saveOrUpdate(entity) is always set.

Also when I delete(entity) I got this

Code:
11:44:28,571 DEBUG DefaultDeleteEventListener:119 - deleting a persistent instance
11:44:28,571 DEBUG DefaultDeleteEventListener:213 - [b]deleting [biblioteca.pojo.Libraryitem#1][/b]
11:44:28,571 DEBUG SessionImpl:1308 - setting cache mode to: GET
11:44:28,574 DEBUG SessionImpl:1308 - setting cache mode to: NORMAL
11:44:28,574 DEBUG SessionImpl:1308 - setting cache mode to: GET
11:44:28,574 DEBUG SessionImpl:1308 - setting cache mode to: NORMAL


As you can see, it attempts to delete [biblioteca.pojo.Libraryitem#1], where 1 is the id of the Libraryitem.

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 15, 2008 11:19 pm 
Newbie

Joined: Mon Sep 15, 2008 12:29 am
Posts: 4
Men I figure out what it was... I feel kinda dumb

When getting the session I was doing..

Code:

//      if (session == null){
//                    session = sessionFactory.openSession();                   
//                }
//                else{
//                    //session.flush();
//                    session.clear();
//                }
//       return session;


instead of just doing..

Code:
return sessionFactory.getCurrentSession();


change that, and put the @Transactional annotation in top of the class.. and that was it.

Thank you so much for your time, and sorry about that..


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.