[hibernate-issues] [Hibernate-JIRA] Commented: (HHH-2919) HQL DELETE and map entity mode
Cédric Chantepie (JIRA)
noreply at atlassian.com
Mon Oct 29 12:56:38 EDT 2007
[ http://opensource.atlassian.com/projects/hibernate/browse/HHH-2919?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_28618 ]
Cédric Chantepie commented on HHH-2919:
---------------------------------------
Doesn't seem to be only due to map mode as the trouble also occurs in pojo one.
Pojo class :
package fr;
public class TestObj {
private String name = null;
private String value = null;
public TestObj() {
}
/**
*/
public final String getName() {
return this.name;
}
/**
*/
public final void setName(final String newName) {
this.name = newName;
}
/**
*/
public final String getValue() {
return this.value;
}
/**
*/
public final void setValue(final String newValue) {
this.value = newValue;
}
public boolean equals(Object o) {
if (o == null || !(o instanceof TestObj)) {
return false;
}
TestObj other = (TestObj) o;
return (((other.name == null && this.name == null) ||
(this.name != null && this.name.equals(other.name))) &&
((other.value == null && this.value == null) ||
(this.value != null && this.value.equals(other.value))));
}
public int hashCode() {
StringBuffer buff = new StringBuffer();
// TODO: use commons-lang HashCodeBuilder
buff.append(this.name).
append(this.value);
return buff.toString().hashCode();
}
}
xx.hbm.xml :
<class name="fr.TestObj"
table="test"
lazy="false">
<id name="name" column="name" type="string" />
<property name="value" column="value" type="string" />
</class>
JUnit test code :
TestObj t = null;
try {
t = new TestObj();
t.setName("Test1");
t.setValue("---");
session.save(t);
} catch (Exception e) {
fail(e.getMessage());
}
try {
t = (TestObj) session.get(TestObj.class, "Test1");
assertNotNull(t);
} catch (Exception e) {
fail(e.getMessage());
}
try {
Query q = session.createQuery("DELETE FROM fr.TestObj t " +
"WHERE t.name = :name");
q.setString("name", "Test1");
assertTrue(q.executeUpdate() == 1);
//WORK:session.delete(t);
} catch (Exception e) {
fail(e.getMessage());
}
try {
TestObj m = (TestObj) session.get(TestObj.class, "Test1");
// still find deleted object
assertNull(m);
} catch (Exception e) {
fail(e.getMessage());
}
> HQL DELETE and map entity mode
> ------------------------------
>
> Key: HHH-2919
> URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-2919
> Project: Hibernate3
> Issue Type: Bug
> Components: caching (L2), core, query-hql
> Affects Versions: 3.2.5
> Environment: org.hibernate.transaction.JDBCTransactionFactory as factory_class, postgresql 8.x with postgresql-8.1-407.jdbc3.jar JDBC driver, Linux 2.6.22-gentoo-r8 i686 Pentium III (Coppermine)
> Reporter: Cédric Chantepie
>
> Cache trouble when deleting object mapped in map mode (dynamic-map) with an HQL DELETE query, where as if deleted with session.delete(...) it works.
> In xxx.hbm.xml :
> <!-- Entity mapping -->
> <class entity-name="Test"
> table="test"
> lazy="false">
> <composite-id>
> <key-property name="name" column="name"
> type="string" />
> <key-property name="type" column="ptype"
> type="integer" />
> </composite-id>
> <property name="value" column="value" type="string" />
> </class>
> <!-- endOf Entity mapping -->
> JUnit test code :
> Map t = null;
> try {
> t = new HashMap(3);
> t.put("name", "Test1");
> t.put("type", new Integer(2));
> t.put("value", "---");
> session.save("Test", t);
> } catch (Exception e) {
> fail(e.getMessage());
> }
> try {
> t = (Map) session.get("Test", (Serializable) t);
> assertNotNull(t);
> } catch (Exception e) {
> fail(e.getMessage());
> }
> try {
> Query q = session.createQuery("DELETE FROM Test t " +
> "WHERE t.name = :name");
> q.setString("name", "Test1");
> assertTrue(q.executeUpdate() == 1);
> //WORK:session.delete("Test", (Serializable) t);
> } catch (Exception e) {
> fail(e.getMessage());
> }
> try {
> Map m = (Map) session.get("Test", (Serializable) t);
> assertNull(m); // fails here, find the deleted object, no ObjectDeletedException
> } catch (Exception e) {
> fail(e.getMessage());
> }
> Maybe that due to composite-id and hashCode/equals support in map mode, maybe cache is not notified of objects deleted by HQL in this map mode.
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://opensource.atlassian.com/projects/hibernate/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
More information about the hibernate-issues
mailing list