IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Hibernate Java Discussion :

[EhCache] Configuration avec Hibernate & Spring


Sujet :

Hibernate Java

  1. #1
    Membre confirmé
    Inscrit en
    Mars 2004
    Messages
    183
    Détails du profil
    Informations forums :
    Inscription : Mars 2004
    Messages : 183
    Par défaut [EhCache] Configuration avec Hibernate & Spring
    Bonsoir,

    Je galère sur la configuration d'ehcache d'hibernate avec Spring

    Voilà une partie du mon applicationContext.xml concernant Hibernate & EhCache

    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
    28
    29
    30
    31
    32
    33
    34
    <bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
          	<property name="dataSource"><ref local="dataSource"/></property>
          	<property name="hibernateProperties">
    	     	<props>
    	       		<prop key="hibernate.dialect">
    	         		org.hibernate.dialect.MySQLDialect
    	       		</prop>
    	       		<prop key="hibernate.show_sql">
    	         		true
    	       		</prop>
     
    	       	    <prop key="hibernate.cache.provider_class">
    	       			net.sf.ehcache.hibernate.EhCacheProvider
    	       		</prop>
    	       		<prop key="hibernate.cache.use_query_cache">
    	       			true
    	       		</prop>
    	       		<prop key="hibernate.cache.use_second_level_cache">
    	       			true
    	       		</prop>
    	       		<prop key="hibernate.cache.use_structured_cache">
    	       			true
    	       		</prop>
    	       		<prop key="hibernate.cache.use_minimal_puts">
    	       			true
    	       		</prop> 
    	     	</props>
    	   	</property>
          	<property name="annotatedClasses">
    			<list>
    				<value>com.leaderinfo.novanet.entity.commons.CurrentSelection</value>
    			</list>
    	  	</property>
       </bean>
    VOilà mon fichier 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
    <ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="ehcache.xsd">
        <diskStore path="C:\ehcache"/>
        <cache name="org.hibernate.cache.StandardQueryCache"
            maxElementsInMemory="1000" 
            timeToLiveSeconds="60" 
            timeToIdleSeconds="60"
            overflowToDisk="false" 
            eternal="false" />
     
        <defaultCache
            maxElementsInMemory="10000"
            eternal="false"
            timeToIdleSeconds="60"
            timeToLiveSeconds="60"
            overflowToDisk="false" />
    </ehcache>
    Je ne comprends pas, je me suis mis dans un test unitaire (et même une JSP), je charge un objet, je le recharge derrière immédiatement et malheureusement hibernate reli en base (show_sql = true me le prouve)

    Comment faire pour que ce dernier fonctionne ?

    Merci a vous

  2. #2
    Membre confirmé
    Inscrit en
    Mars 2004
    Messages
    183
    Détails du profil
    Informations forums :
    Inscription : Mars 2004
    Messages : 183
    Par défaut
    personne ?

  3. #3
    Membre Expert
    Profil pro
    Inscrit en
    Août 2006
    Messages
    3 277
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Août 2006
    Messages : 3 277
    Par défaut
    As-tu utilisé l'annotation @Cache sur tes entités ?

  4. #4
    Membre confirmé
    Inscrit en
    Mars 2004
    Messages
    183
    Détails du profil
    Informations forums :
    Inscription : Mars 2004
    Messages : 183
    Par défaut
    Non ... peux tu m'en dire plus ?

  5. #5
    Membre Expert
    Profil pro
    Inscrit en
    Août 2006
    Messages
    3 277
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Août 2006
    Messages : 3 277
    Par défaut
    C'est pour déclarer les objets qui seront dans le cache.
    Je te laisse lire la documentation sur le sujet.

  6. #6
    Membre confirmé
    Inscrit en
    Mars 2004
    Messages
    183
    Détails du profil
    Informations forums :
    Inscription : Mars 2004
    Messages : 183
    Par défaut
    Je viens de jeter un oeil et faire un test, non concluant.

    Quelqu'un à un source qui fonctionne bien ? Apparemment ne suis pas le seul à "galérer" avec le cache ....

    Ce qui m'importe, c'est qu'hibernate ne refasse pas sans cesse ses select à la base de données

    Merci

  7. #7
    Membre Expert
    Profil pro
    Inscrit en
    Août 2006
    Messages
    3 277
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Août 2006
    Messages : 3 277
    Par défaut
    Montre nous un peu de code, celui de ton entité, et de ton test.

  8. #8
    Membre confirmé
    Inscrit en
    Mars 2004
    Messages
    183
    Détails du profil
    Informations forums :
    Inscription : Mars 2004
    Messages : 183
    Par défaut
    Ok

    Voici l'entite concernée

    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
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    package com.leaderinfo.novanet.entity.commons;
     
    import java.io.Serializable;
     
    import javax.persistence.Column;
    import javax.persistence.Entity;
    import javax.persistence.Id;
    import javax.persistence.Table; org.hibernate.annotations.Cache;
    import org.hibernate.annotations.CacheConcurrencyStrategy;
     
    @Entity
    @Table(name = "currentselection")
    public class CurrentSelection implements Serializable {
    	private static final long serialVersionUID = 3225464404301611935L;
    	@Id 
    	@Column(name = "login", nullable = false)
    	private String login;
    	@Column(name = "societeuser", nullable = false)
    	private String societeuser;
    	@Column(name = "numeroClient", nullable = true)
    	private Long numeroClient;
    	@Column(name = "numeroPolice", nullable = true)
    	private String numeroPolice;
    	@Column(name = "numeroSin", nullable = true)
    	private Long numeroSin;
     
    	public CurrentSelection(){}
     
    	public String getLogin() {
    		return login;
    	}
    	public void setLogin(String login) {
    		this.login = login;
    	}
    	public String getSocieteuser() {
    		return societeuser;
    	}
    	public void setSocieteuser(String societeuser) {
    		this.societeuser = societeuser;
    	}
    	public Long getNumeroClient() {
    		return numeroClient;
    	}
    	public void setNumeroClient(Long numeroClient) {
    		this.numeroClient = numeroClient;
    	}
    	public String getNumeroPolice() {
    		return numeroPolice;
    	}
    	public void setNumeroPolice(String numeroPolice) {
    		this.numeroPolice = numeroPolice;
    	}
    	public Long getNumeroSin() {
    		return numeroSin;
    	}
    	public void setNumeroSin(Long numeroSin) {
    		this.numeroSin = numeroSin;
    	}
    }
    Et le test

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    ICurrentSelectionService currentSelectionService = (ICurrentSelectionService) SpringBeanProvider.getBean("currentSelectionService");
    CurrentSelection currentSelection = currentSelectionService.find("demo2");
    out.println(currentSelection.getLogin());
    A chaque fois je revois dans les loggues la requête de selection faite par Hibernate

  9. #9
    Membre Expert
    Profil pro
    Inscrit en
    Août 2006
    Messages
    3 277
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Août 2006
    Messages : 3 277
    Par défaut
    Déjà je ne vois pas l'annotation @cache dans ton entité.
    Ensuite, que fait la méthode currentSelectionService.find? Est-ce une requête HQL, un load.. ?

  10. #10
    Membre confirmé
    Inscrit en
    Mars 2004
    Messages
    183
    Détails du profil
    Informations forums :
    Inscription : Mars 2004
    Messages : 183
    Par défaut
    Voila le contenu de ma méthode find

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    public T find(Serializable id) {
    		T entity = null;
    		try {
    			entity = this.localDao.find(id);
    			return entity;
    		} catch (Exception e) {
    			logger.error("", e);
    		}
    		return entity;
    	}
    --> DAO

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    public T find(Serializable id) {
    		return (T) this.sessionFactory.getCurrentSession().get(this.entityClass, id);
    	}

Discussions similaires

  1. Configuration MySql avec Hibernate et Spring
    Par _Babar_ dans le forum Frameworks Web
    Réponses: 34
    Dernier message: 11/10/2010, 11h25
  2. [Data] erreur many to one avec hibernate et spring
    Par hanen14 dans le forum Spring
    Réponses: 2
    Dernier message: 13/04/2010, 13h37
  3. [Data] configuration applicationContext spring avec hibernate
    Par riderfun dans le forum Spring
    Réponses: 4
    Dernier message: 25/05/2009, 15h03
  4. Probleme de recuperation d'une liste avec Hibernate et Spring
    Par fabiolerusse dans le forum Hibernate
    Réponses: 4
    Dernier message: 22/05/2008, 15h04
  5. [Data] Problème de lazy avec hibernate et Spring
    Par Invité dans le forum Spring
    Réponses: 3
    Dernier message: 20/02/2008, 20h03

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo