开发者

2nd level cache and session.save

The collection on an entity in the cache is not refresh after a session.delete.

Here is my relation :

- a model can have 0 to N bookmarks used for a specific user.

- the primaky key of a model is an id

- the primary key of the bookmark is the couple (idModele,loginUser)

The problem is that if i save a model 1 with one bookmark. They are put in the 2nd level cache. If i'm using bookmarkDao.delete in one transaction to remove this bookmark, it is still in modele.getBookmarks() even in a new transaction. The cache seems to not have been update.

Here are my hbm files:

Model

 <class name="Modele" table="modele"  batch-size="10">
<cache usage="read-write"/>
 <id name="id" column="id_composant" unsaved-value="0">
  <generator class="sequence">
    <param name="sequence">composant_id_composant_seq</param>
  </generator>
</id>

<set name="bookmarks" table="bookmark" cascade="all" access="field" >
  <cache usage="read-write"/>
  <key column="id_modele" />
  <element column="username" type="string"/>
</set>

Bookmark

 <class name="Bookmark" table="bookmark">  
 <cache usage="read-write"/>
<composite-id>
  <key-many-to开发者_高级运维-one name="modele" column="id_modele" access="field" />
  <key-property name="username" column="username"/>
</composite-id>
</class>

The classes

public class Bookmark implements Serializable {
private static final long serialVersionUID = 1L;

private Modele modele;
private String username;

public Modele getModele() {
    return modele;
}
public void setModele(Modele modele) {
    this.modele = modele;
}

public String getUsername() {
    return username;
}
public void setUsername(String username) {
    this.username = username;
}
@Override
public int hashCode() {

    final int prime = 31;
    int result = 1;
    result = prime * result + ((modele == null) ? 0 : modele.hashCode());
    result = prime * result + ((username == null) ? 0 : username.hashCode());
    return result;
}
@Override
public boolean equals(Object obj) {
    if (this == obj)
        return true;
    if (obj == null)
        return false;
    if (getClass() != obj.getClass())
        return false;
    Favori other = (Favori) obj;
    if (modele == null) {
        if (other.modele != null)
            return false;
    } else if (!modele.equals(other.modele))
        return false;
    if (username == null) {
        if (other.username != null)
            return false;
    } else if (!username.equals(other.username))
        return false;
    return true;
}

}

Do i miss something ?

I'm using Hibernate Core 3.6.3.Final & Ehcache 2.2.0 with Maven, spring core, tx...3.0.

Thanks in advance for your help.


The session is the first-level cache, not the second-level cache.

Without more information about your config and the error you get, it's hard to help more.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜