-->
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: Hibernate3: Problems with delete("from...") query
PostPosted: Thu Dec 09, 2004 9:42 am 
Newbie

Joined: Thu Dec 09, 2004 9:32 am
Posts: 2
Hibernate version: 3.0

I am using Hibernate 3.0 Spring. I have a simple Java bean as follows:

Product.java
-----------------------------------
public class Product {

private int id;
private String name;

//getters and setters follow
...

}


The mapping document looks like this:

Product.hbm.xml
------------------------------------
<hibernate-mapping>

<class name="Product" table="PRODUCT">
<id name="id" column="PROD_ID">
<generator class="native"/>
</id>
<property name="name" column="PROD_NAME"/>
</class>

</hibernate-mapping>

From a Test class, when I try to delete a row as follows:

public class TestProductDao {

public void delete(int prodID) {
getHibernateTemplate().delete("from Product where id=" + prodID);
}

}

I get a error as follows:
org.springframework.orm.hibernate3.HibernateSystemException: Unknown entity: java.lang.String; nested exception is org.hibernate.MappingException: Unknown entity: java.lang.String
org.hibernate.MappingException: Unknown entity: java.lang.String
at org.hibernate.impl.SessionFactoryImpl.getEntityPersister
(SessionFactoryImpl.java:444)

This implementation, however, works fine with Hibernate 2.1 + Spring.

Any thoughts on this?
Thanks a lot,
-Vineet


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 09, 2004 12:28 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
How are you using Hibernate3 with Spring? Have they already added support for Hibernate3?

In Hibernate3, that delete method (the ability to delete entities based on the result of a query) has been deprecated. All these deprecated Session methods have been moved to the org.hibernate.classic.Session interface. Now org.hibernate.Session does still have a delete(Object) method, but it is obviously intended for deletion of a single entity. So when you call session.select("my query), Hibernate thinks you are trying to delete the string "my query".

The reason we deprecated delete(String query)? Because once it is better defined, we will be adding support for EJB3-style bulk delete operations, which is a better way to do this.

In the meantime, if you need this functionality, just do what Session.delete(String query) did itself internally:
1) perform the query, getting the list of matching entities;
2) iterate the list, calling session.delete(entity) for each entity in the list.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 10, 2004 1:19 am 
Newbie

Joined: Thu Dec 09, 2004 9:32 am
Posts: 2
If I am not wrong, Spring has not yet officially supported Hiberbate 3. There is however a patch available which makes Spring compatible with Hbn 3.

Anyway, thanks a lot for the clarification Steve.


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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.