Bonjour,

J'ai un soucis avec la mise en cache d'un mapping sous websphere 6,
je souhaite mapper un code statut en un autre via une table de mapping avec une mise en cache.

Sous eclipse lors de mes tests de mise en cache avec le même code ou presque (c'est a dire sans Session Bean) cela semble fonctionner:
i.e lorsque je fais un changement en base des valeurs, les modification ne prennent pas effet directement dans l'application car le cache est renouvelé qu'a partir de nn secondes, les nn secondes passé le cache est a jour.

Lorsque j'applique la même "recette" dans mon SessionBean InterfaceManagerbean le cache ne semble pas fonctionner, les modifications en base de mes valeurs celle-ci sont instantanément prises en compte.


Quelqu'un aurait une idée sur l'origine du problème ?


Extrait de mon fichier « InterfaceManagerBean.java » :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
public void treatDemand(){
 
[…..]
 
StatusMappingManager mappingStatus = new StatusMappingManager();
 
      for (int i = 1; i <= 100; i++) { Transaction tx = SessionManager.getSession().beginTransaction();
      Status statusMappe = mappingStatus.findMappingBySourceStatus(statusNonMappe); 
      tx.commit(); 
      System.err.println("STATUT: " + statusMappe.getStatus()+"");
      SessionManager.closeSession(); 
      }
 
[….]
}

Extrait de mon fichier « class StatusMappingManager.java » :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
public class StatusMappingManager {
    public Status findMappingBySourceStatus(String sourceStatus) {
        return (Status) SessionManager.currentSession().createQuery("from Status where sourceStatus = :sourceStatus").setParameter("sourceStatus", sourceStatus).uniqueResult();
    }
 
    public List getMappingStatus() {
        return SessionManager.currentSession().createQuery("from Status order by sourceStatus").setCacheable(true).list();
    }
}

Extrait de mon fichier « class Status.java » :

public class Status implements Serializable {
private static final long serialVersionUID = 1L;
private int status;
private String sourceStatus;
private String statusFlag;

public Status() {
}

/**
* @param status
* @param sourceStatus
* @param statusFlag
*/
public Status(int status, String sourceStatus, String statusFlag) {
super();
this.status = status;
this.sourceStatus = sourceStatus;
this.statusFlag = statusFlag;
}

/**
* @return Returns the sourceStatus.
*/
[….]

Mon fichier de mapping “x_config_mapping_t.hbm.xml”;

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"  "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="com.intf.cmp">
<class name="Status" table="X_CONFIG_STATUS_MAPPING_T">
  <cache usage="read-only" region="maregion"/>
  <id name="sourceStatus" type="string">
            <column name="SOURCE_STATUS" length="2" />
            <generator class="assigned" />
  </id>
  <property name="status" type="int" column="STATUS"/>
  <property name="statusFlag" type="string" column="STATUS_FLAG"/>
</class>
</hibernate-mapping>

Mon fichier de config “hibernate.cfg.xml”;


Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
        "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
        "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
    <session-factory>
        <!-- Database connection settings -->
        <property name="hibernate.connection.driver_class">oracle.jdbc.OracleDriver</property>
 
        <property name="hibernate.connection.url">jdbc:oracle:thin:@XXX:1529:XXXX</property>
        <property name="hibernate.connection.username">XXX</property>
        <property name="hibernate.connection.password">XXX</property>
 
        <!-- JDBC connection pool (use the built-in) -->
        <property name="hibernate.connection.pool_size">1</property>
        <!-- SQL dialect -->
        <property name="hibernate.dialect">org.hibernate.dialect.Oracle9Dialect</property>
        <!-- Enable Hibernate's automatic session context management -->
        <property name="hibernate.current_session_context_class">thread</property>
 
        <!-- Enable second-level EHCache-->
        <property name="hibernate.cache.use_second_level_cache">true</property>
        <property name="hibernate.cache.provider_class">org.hibernate.cache.EhCacheProvider</property>
        <property name="hibernate.cache.use_query_cache">true</property>
        <mapping resource="com/intf/cmp/x_config_mapping_t.hbm.xml"/>
    </session-factory>
</hibernate-configuration>

Mon fichier de config “ehcache.xml”;

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
<ehcache>
	<diskStore path="java.io.tmpdir" />
	<defaultCache 
		maxElementsInMemory="10000" 
		eternal="false"
		timeToIdleSeconds="6" 
		timeToLiveSeconds="150000" 
		overflowToDisk="true"
		diskPersistent="false" 
		diskExpiryThreadIntervalSeconds="300000"
	/>
	<cache name="com.intf.cmp.Status"
		maxElementsInMemory="5000" 
		eternal="false" 
		overflowToDisk="false"
		timeToIdleSeconds="10" 
		timeToLiveSeconds="20"
	/>
</ehcache>