Hi,
I hope you can help me!
I use jbosscache as a 2nd level cache for hibernate entity manager.
My problem is that the cache does'nt take care of cascade actions. If i add or remove from a collection and merging the owning class the db state is ok, but the cache contains the old data. The facts:
Hibernate version:
jboss 4.0.4 GA
hibernate-3.2
JBossCache 1.4.0.GA
Mapping documents:
persistence config:
Code:
<persistence>
<persistence-unit name="xxx">
<jta-data-source>java:/PostgresDS</jta-data-source>
<properties>
<property name="hibernate.dialect"
value="org.hibernate.dialect.PostgreSQLDialect" />
<property name="hibernate.cache.provider_class"
value="org.jboss.ejb3.entity.TreeCacheProviderHook" />
<property name="hibernate.treecache.mbean.object_name"
value="jboss.cache:service=TreeCache" />
<!-- JDBC connection pool (use the built-in) -->
<property name="hibernate.cache.use_query_cache"
value="true" />
<property name="hibernate.default_batch_fetch_size"
value="10" />
<!-- Echo all executed SQL to stdout -->
<property name="hibernate.show_sql">true</property>
</properties>
</persistence-unit>
</persistence>
cache config:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<server>
<classpath codebase="./lib" archives="jboss-cache.jar, jgroups.jar" />
<mbean code="org.jboss.cache.TreeCache"
name="jboss.cache:service=TreeCache">
<depends>jboss:service=Naming</depends>
<depends>jboss:service=TransactionManager</depends>
<attribute name="NodeLockingScheme">PESSIMISTIC</attribute>
<attribute name="IsolationLevel">REPEATABLE_READ</attribute>
<attribute name="CacheMode">LOCAL</attribute>
<attribute name="UseReplQueue">false</attribute>
<attribute name="ReplQueueInterval">0</attribute>
<attribute name="ReplQueueMaxElements">0</attribute>
<attribute name="LockAcquisitionTimeout">15000</attribute>
<attribute name="EvictionPolicyConfig">
<config>
<attribute name="wakeUpIntervalSeconds">5</attribute>
<!-- Cache wide default -->
<region name="/_default_"
policyClass="org.jboss.cache.eviction.LRUPolicy">
<attribute name="maxNodes">10000</attribute>
<attribute name="timeToLiveSeconds">10000</attribute>
</region>
</config>
</attribute>
<attribute name="UseRegionBasedMarshalling">false</attribute>
</mbean>
</server>
mapping:
Code:
/**
* Felhasznalok generated by hbm2java
*/
@Entity
@Cache(usage = CacheConcurrencyStrategy.TRANSACTIONAL)
@Table(name = "felhasznalok", schema = "privilegiumok", uniqueConstraints = { @UniqueConstraint(columnNames = { "f_nev" }) })
public class Felhasznalok implements java.io.Serializable {
// Fields
private int uid;
.
.
.
private List<Kedvencek> kedvenceks = new ArrayList<Kedvencek>(0);
// Property accessors
@Id
@Column(name = "uid", unique = true, nullable = false, insertable = true, updatable = true)
public int getUid() {
return this.uid;
}
.
.
.
@OneToMany(fetch = FetchType.LAZY, mappedBy = "felhasznalok")
@OrderBy("id")
@Cache(usage = CacheConcurrencyStrategy.TRANSACTIONAL)
@org.hibernate.annotations.Cascade( {
org.hibernate.annotations.CascadeType.ALL,
org.hibernate.annotations.CascadeType.DELETE_ORPHAN })
public List<Kedvencek> getKedvenceks() {
return this.kedvenceks;
}
public void setKedvenceks(List<Kedvencek> kedvenceks) {
this.kedvenceks = kedvenceks;
}
}
Code:
/**
* Kedvencek generated by hbm2java
*/
@Entity
@Cache(usage = CacheConcurrencyStrategy.TRANSACTIONAL)
@Table(name = "kedvencek", schema = "privilegiumok", uniqueConstraints = {})
@org.hibernate.annotations.GenericGenerator(name = "SEQ_GEN", strategy = "sequence", parameters = { @Parameter(name = "sequence", value = "privilegiumok.kedvencek_k_index_seq") })
public class Kedvencek implements java.io.Serializable {
// Fields
private int KIndex;
private Felhasznalok felhasznalok;
// Property accessors
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "SEQ_GEN")
@Column(name = "k_index", unique = true, nullable = false, insertable = true, updatable = true)
public int getKIndex() {
return this.KIndex;
}
.
.
.
@ManyToOne(cascade = {}, fetch = FetchType.LAZY)
@JoinColumn(name = "uid", unique = false, nullable = false, insertable = true, updatable = true)
public Felhasznalok getFelhasznalok() {
return this.felhasznalok;
}
public void setFelhasznalok(Felhasznalok felhasznalok) {
this.felhasznalok = felhasznalok;
}
}
Code between sessionFactory.openSession() and session.close(): Kedvencek kedvencek = new Kedvencek();
kedvencek.setFelhasznalok(felhasznalo);
kedvencek.setId(Integer.parseInt(i.getId()));
kedvencek.setName(i.getValue());
felhasznalo.getKedvenceks().add(kedvencek);
felhasznalokService.merge(felhasznalo);
Full stack trace of any exception that occurs:There's no exception! Persisiting works fine. But my cache does not update itself! The "Felhasznalok" class's "Kedvencek" collection contains the same data in the cache before merging the entity. DB state is correct. (for adding and deleting too )
Name and version of the database you are using:postgresql 8[/code]