-->
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.  [ 9 posts ] 
Author Message
 Post subject: Error on Deleting Records
PostPosted: Wed Jun 27, 2007 2:07 am 
Newbie

Joined: Wed Jun 27, 2007 1:58 am
Posts: 6
Hi I am trying to delete records from the db. First of all I am using
find(String query) method to fetch the records from the db
and then i am using
hibernateTemplate.delete(Object obj)

but when i do this , its throwing the following exception:-

Code:
Caused by:
org.hibernate.MappingException: Unknown entity: [Ljava.lang.Object;
        at org.hibernate.impl.SessionFactoryImpl.getEntityPersister(SessionFactoryImpl.java:548)
        at org.hibernate.impl.SessionImpl.getEntityPersister(SessionImpl.java:1338)
        at org.hibernate.event.def.DefaultDeleteEventListener.onDelete(DefaultDeleteEventListener.java:67)
        at org.hibernate.event.def.DefaultDeleteEventListener.onDelete(DefaultDeleteEventListener.java:49)
        at org.hibernate.impl.SessionImpl.fireDelete(SessionImpl.java:766)
        at org.hibernate.impl.SessionImpl.delete(SessionImpl.java:744)
        at org.springframework.orm.hibernate3.HibernateTemplate$25.doInHibernate(HibernateTemplate.java:780)
        at org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:362)
        at org.springframework.orm.hibernate3.HibernateTemplate.delete(HibernateTemplate.java:774)
        at org.springframework.orm.hibernate3.HibernateTemplate.delete(HibernateTemplate.java:770)


not sure why.....

Please help.
Thanks in advance.

[/code]


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 27, 2007 2:13 am 
Expert
Expert

Joined: Tue Jan 30, 2007 12:45 am
Posts: 283
Location: India
Hi Code_Guru,

Before deleting it should be type cast to exact Mapped class

hibernateTemplate.delete(Object obj)

_________________
Dharmendra Pandey


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 27, 2007 2:26 am 
Newbie

Joined: Wed Jun 27, 2007 1:58 am
Posts: 6
Thanks Dharmendra...

I tried by type casting to the desired class
as

for( i =0 ; i < result.size(); i++) {
ABC abc = (ABC) result.get(i);
hibernateTemplate.delete(abc);
}

Now its throwing ClassCast Exception.
java.lang.ClassCastException: [Ljava.lang.Object;


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 27, 2007 4:56 am 
Expert
Expert

Joined: Tue Jan 30, 2007 12:45 am
Posts: 283
Location: India
Might be it is proxy class.Load that class by session.get() and try to delete it .

Post your hbm file .we will try to dig it

_________________
Dharmendra Pandey


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 27, 2007 5:49 am 
Newbie

Joined: Wed Jun 27, 2007 1:58 am
Posts: 6
My sessionfactory configuration look this:-

Code:
<bean id="sessionFactory"
      class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
      <property name="dataSource">
         <ref bean="dataSource" />
      </property>
      <property name="mappingDirectoryLocations">
         <list>
            <value>/WEB-INF/config/mapping</value>
         </list>
      </property>
      <property name="hibernateProperties">
         <props>
            <prop key="hibernate.dialect">
               org.hibernate.dialect.OracleDialect
            </prop>
            <prop key="hibernate.show_sql">false</prop>
            <prop key="hibernate.cache.use_query_cache">true</prop>
            <prop key="hibernate.generate_statistics">true</prop>
            <prop key="hibernate.cache.use_structured_entries">
               true
            </prop>
            <prop key="hibernate.session_factory_name">
               test/one
            </prop>
            <prop key="hibernate.cache.use_second_level_cache">
               true
            </prop>
            <prop key="hibernate.cache.provider_class">
               org.hibernate.cache.TreeCacheProvider
            </prop>
            <prop key="hibernate.treecache.objectName">
               jboss.cache:service=TreeCache
            </prop>
         </props>
      </property>
</bean>


Please guide me if i am missing something.

Thanks in advance


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 27, 2007 5:53 am 
Newbie

Joined: Wed Jun 27, 2007 1:58 am
Posts: 6
And my hbm file from which contains the mapping is :-

Code:
<hibernate-mapping package="com.a.b.c.ABC">
   <class name="TableDO" table="table">
      <id name="tableId" column="table_id">
         <generator class="increment"/>
      </id>   
      <property name="nameId" column="name_id"/>
      <property name="createdDate" column="created_date"/>
      <property name="deletedDate" column="deleted_date"/>      
   </class>
</hibernate-mapping>


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 27, 2007 6:15 am 
Expert
Expert

Joined: Tue Jan 30, 2007 12:45 am
Posts: 283
Location: India
might be your problem in method which contain

for( i =0 ; i < result.size(); i++) {
ABC abc = (ABC) result.get(i);
hibernateTemplate.delete(abc);
}


code . post full code of that method and cross check that TableDO class is mapped with hibernate or not. I have not seen how to do with
<property name="mappingDirectoryLocations">
<list>
<value>/WEB-INF/config/mapping</value>
</list>
</property>

_________________
Dharmendra Pandey


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 27, 2007 7:51 am 
Newbie

Joined: Wed Jun 27, 2007 1:58 am
Posts: 6
the method contains

Code:
public void deleteRecord(String currentDate) {
StringBuffer queryString = new StringBuffer();
queryString.append("Select tableDO.tableId , tableDO.nameId from TableDO tableDO ");
queryString.append(" where tableDO.createdDate < '");
queryString.append(currentDate);
queryString.append("'");
List<TableDO> result =(List<TableDO>) this.hibernateTemplate.find(queryString.toString());
for(int i = 0 ; i < result.size() ;i++) {
     TableDO table = (TableDO) result.get(i);
     this.hibernateTemplate.delete(table);
}
}

and
/WEB-INF/config/mapping this path conatins all the hbm files.

and the file Table.hbm.xml file conatins
Code:
<hibernate-mapping package="com.a.b.c.ABC">
   <class name="TableDO" table="table">
      <id name="tableId" column="table_id">
         <generator class="increment"/>
      </id>   
      <property name="nameId" column="name_id"/>
      <property name="createdDate" column="created_date"/>
      <property name="deletedDate" column="deleted_date"/>     
   </class>
</hibernate-mapping>


Thanks in advance...


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 28, 2007 3:20 am 
Expert
Expert

Joined: Tue Jan 30, 2007 12:45 am
Posts: 283
Location: India
Hi Code_Guru,

change it to

queryString.append("Select tableDO from TableDO tableDO ");
queryString.append(" where tableDO.createdDate < '");

_________________
Dharmendra Pandey


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