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 :

Problème SaveOrUpdate avec entity-name


Sujet :

Hibernate Java

  1. #1
    Membre du Club
    Inscrit en
    Avril 2003
    Messages
    71
    Détails du profil
    Informations personnelles :
    Âge : 41

    Informations forums :
    Inscription : Avril 2003
    Messages : 71
    Points : 65
    Points
    65
    Par défaut Problème SaveOrUpdate avec entity-name
    Bonjour j'ai un petit soucis lors d'une mise à jour de données je m'explique, je dispose d'une classe Rebut qui représente des rejets sur une ligne de production :

    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
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    public class Rebut implements Serializable{
     
    	private static final long serialVersionUID = -662108058222368049L;
    	private RebutItem rebut;
    	private Produit produit;
    	private ProductionLine ligne;
    	private Date date;
    	private String poste;
     
    	private int quantite;
    	private int quantiteReintegree;
    	private int quantiteFinale;
     
    	private int semaine;
    	private int mois;
    	private int annee;
     
    	private String ordre;
    	private String operation;
    	private String code_rebut;
    	private String code_ligne;
     
    	public String getCode_ligne() {
    		return code_ligne;
    	}
    	public void setCode_ligne(String code_ligne) {
    		this.code_ligne = code_ligne;
    	}
    	public String getCode_rebut() {
    		return code_rebut;
    	}
    	public void setCode_rebut(String code_rebut) {
    		this.code_rebut = code_rebut;
    	}
    	public String getOperation() {
    		return operation;
    	}
    	public void setOperation(String operation) {
    		this.operation = operation;
    	}
    	public String getOrdre() {
    		return ordre;
    	}
    	public void setOrdre(String ordre) {
    		this.ordre = ordre;
    	}
    	public int getAnnee() {
    		return annee;
    	}
    	public void setAnnee(int annee) {
    		this.annee = annee;
    	}
    	public int getMois() {
    		return mois;
    	}
    	public void setMois(int mois) {
    		this.mois = mois;
    	}
    	public int getSemaine() {
    		return semaine;
    	}
    	public void setSemaine(int semaine) {
    		this.semaine = semaine;
    	}
    	public Date getDate() {
    		return date;
    	}
    	public void setDate(Date date) {
    		this.date = date;
    	}
    	public ProductionLine getLigne() {
    		return ligne;
    	}
    	public void setLigne(ProductionLine ligne) {
    		this.ligne = ligne;
    	}
    	public String getPoste() {
    		return poste;
    	}
    	public void setPoste(String poste) {
    		this.poste = poste;
    	}
    	public int getQuantite() {
    		return quantite;
    	}
    	public void setQuantite(int quantite) {
    		this.quantite = quantite;
    	}
    	public RebutItem getRebut() {
    		return rebut;
    	}
    	public void setRebut(RebutItem rebut) {
    		this.rebut = rebut;
    	}
    	public Produit getProduit() {
    		return produit;
    	}
    	public void setProduit(Produit produit) {
    		this.produit = produit;
    	}
    	public int getQuantiteFinale() {
    		return quantiteFinale;
    	}
    	public void setQuantiteFinale(int quantiteFinale) {
    		this.quantiteFinale = quantiteFinale;
    	}
    	public int getQuantiteReintegree() {
    		return quantiteReintegree;
    	}
    	public void setQuantiteReintegree(int quantiteReintegree) {
    		this.quantiteReintegree = quantiteReintegree;
    	}	
    }
    Cette classe est mappée pour être persistée via hibernate dans une base SQL Server voici le mapping :

    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
    <hibernate-mapping>
     
    	<class name="javabeans.production.Rebut" table="E_DECLARATION_QUANTITE" entity-name="Rebut">
    		<composite-id> 
               <key-property  name="date" type="date"  column="DATE_CALENDRIER" /> 
               <key-property name="poste" column="CODE_EQUIPE" />          
    	        <key-many-to-one name="produit" class="javabeans.production.Produit">
    	        	<column name="NUMERO_ORDRE"/>
    	        	<column name="NUMERO_OPERATION"/>
    	        </key-many-to-one>
    			<key-many-to-one name="rebut" class="javabeans.production.RebutItem" column="CODE_REBUT"/>
    			<key-many-to-one name="ligne" class="javabeans.production.ProductionLine" column="CODE_POSTE"/>
            </composite-id>
     
            <property name="quantite" column="QUANTITE"/>
            <property name="semaine" type="integer">
            	<formula>dbo.SemaineIso(DATE_CALENDRIER)</formula>
            </property>
            <property name="annee" type="integer">
            	<formula>year(DATE_CALENDRIER)</formula>
            </property>
            <property name="mois" type="integer">
            	<formula>month(DATE_CALENDRIER)</formula>
            </property>
        </class>
     
    	<class name="javabeans.production.Rebut" table="E_DECLARATION_QUANTITE" entity-name="RebutUpdate">
    		<composite-id> 
    			<key-property name="date" type="date"  column="DATE_CALENDRIER" /> 
    			<key-property name="poste" column="CODE_EQUIPE" />          
    	                <key-property name="ordre" column="NUMERO_ORDRE"/>     
    	                <key-property name="operation" column="NUMERO_OPERATION"/>
    			<key-property name="code_rebut" column="CODE_REBUT"/>
    			<key-property name="code_ligne" column="CODE_POSTE"/>
            </composite-id>
     
            <property name="quantite" column="QUANTITE"/> 
        </class>
    </hibernate-mapping>
    lorsque j'utilise l'entité "Rebut" pour effectuer des select, aucun problème par contre dès que je tente de faire une insertion en utilisant l'entitée "RebutUpdate" j'ai une exception

    org.hibernate.MappingException: Unknown entity: RebutUpdate
    at org.hibernate.impl.SessionFactoryImpl.getEntityPersister(SessionFactoryImpl.java:569)
    at org.hibernate.impl.SessionImpl.getEntityPersister(SessionImpl.java:1089)
    at org.hibernate.engine.ForeignKeys.isTransient(ForeignKeys.java:180)
    at org.hibernate.event.def.AbstractSaveEventListener.getEntityState(AbstractSaveEventListener.java:409)
    at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.performSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:82)
    at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:69)
    at org.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java:468)
    at dao.hibernate.production.HibernateRebutDAO.saveRebut(HibernateRebutDAO.java:158)
    at actions.production.RebutSaisieDispatchAction.save(RebutSaisieDispatchAction.java:131)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:585)
    at org.apache.struts.actions.DispatchAction.dispatchMethod(DispatchAction.java:274)
    at org.apache.struts.actions.DispatchAction.execute(DispatchAction.java:194)
    at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:419)
    at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:224)
    at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196)
    at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:432)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
    at net.sf.jguard.authentication.http.AccessFilter.authorize(AccessFilter.java:672)
    at net.sf.jguard.authentication.http.AccessFilter.doFilter(AccessFilter.java:436)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:869)
    at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:667)
    at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
    at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80)
    at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
    at java.lang.Thread.run(Thread.java:595)
    voila le code de l'insertion :

    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
    public void saveRebut(Rebut r){
    		Session session = HibernateSessionFactory.currentSession();
    		try{
    			Transaction tx = session.beginTransaction();
    			session.saveOrUpdate("RebutUpdate",r);
    			tx.commit();
    		}
    		catch(Exception e){
    			e.printStackTrace();
    		}
    		finally{
    			try{
    				HibernateSessionFactory.closeSession();
    			}
    			catch(Exception e1){
    				e1.printStackTrace();
    			}
    		}
    	}
    Si vous avez une piste de réponse je suis preneur merci d'avance
    Si tu ne peut pas battre ton ordinateur aux echecs, essaye le kick boxing

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

    Informations forums :
    Inscription : Août 2006
    Messages : 3 274
    Points : 4 141
    Points
    4 141
    Par défaut
    et avec un simple :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    session.saveOrUpdate(r);

  3. #3
    Membre du Club
    Inscrit en
    Avril 2003
    Messages
    71
    Détails du profil
    Informations personnelles :
    Âge : 41

    Informations forums :
    Inscription : Avril 2003
    Messages : 71
    Points : 65
    Points
    65
    Par défaut
    Euh non pas vraiment...
    En fait la classe "javabeans.production.Rebut" est mappée deux fois :
    - une fois sous l'entity-name Rebut
    - une autre fois sous l'entity-name RebutUpdate

    la première est utilisée pour les select et la deuxième uniquement pour les insert ou les update.
    Donc un simple
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    session.saveOrUpdate(r);
    ne suffit pas à mon avis (d'ailleur la pratique confirme mon avis )
    Si tu ne peut pas battre ton ordinateur aux echecs, essaye le kick boxing

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

    Informations forums :
    Inscription : Août 2006
    Messages : 3 274
    Points : 4 141
    Points
    4 141
    Par défaut
    Ok, je n'avais pas lu ton code suffisament bien.
    Dans ce cas, je ne sais pas répondre, désolé.


    Juste pour info, pourquoi as-tu besoin de mapper deux fois ta classe ?
    Quel est l'intérêt d'en avoir une pour les select et l'autre pour les insert, update ?
    Ce n'est pas une critique, c'est juste pour comprendre.

  5. #5
    Membre du Club
    Inscrit en
    Avril 2003
    Messages
    71
    Détails du profil
    Informations personnelles :
    Âge : 41

    Informations forums :
    Inscription : Avril 2003
    Messages : 71
    Points : 65
    Points
    65
    Par défaut
    Citation Envoyé par fr1man
    Ok, je n'avais pas lu ton code suffisament bien.
    Dans ce cas, je ne sais pas répondre, désolé.


    Juste pour info, pourquoi as-tu besoin de mapper deux fois ta classe ?
    Quel est l'intérêt d'en avoir une pour les select et l'autre pour les insert, update ?
    Ce n'est pas une critique, c'est juste pour comprendre.
    En fait j'avais fait ainsi parceque j'avais des problèmes avec les clef étrangères lors des insert / update, j'ai trouvé une solution sur le net qui préconise un mapping du genre :

    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
    <hibernate-mapping>
    	<class name="javabeans.production.Rebut" table="E_DECLARATION_QUANTITE">
    		<composite-id>
    			<key-property name="date" type="date" column="DATE_CALENDRIER"/> 
    			<key-property name="poste" column="CODE_EQUIPE" />          
    			<key-property name="ordre" column="NUMERO_ORDRE"/>     
    			<key-property name="operation" column="NUMERO_OPERATION"/>
    			<key-property name="code_rebut" column="CODE_REBUT"/>
    			<key-property name="code_ligne" column="CODE_POSTE"/>
    			<key-property name="typeRebut" column="TYPE_QUANTITE"/>
    		</composite-id>
    		<property name="quantite" column="QUANTITE"/>
     
    		<many-to-one name="rebut" class="javabeans.production.RebutItem" column="CODE_REBUT" update="false" insert="false"/>
    		<many-to-one name="ligne" class="javabeans.production.ProductionLine" column="CODE_POSTE" update="false" insert="false"/>
    		<many-to-one name="produit" class="javabeans.production.Produit" update="false" insert="false">
    			<column name="NUMERO_ORDRE"/>
    			<column name="NUMERO_OPERATION"/>
    		</many-to-one>
     
    		<property name="semaine" type="integer">
    			<formula>dbo.SemaineIso(DATE_CALENDRIER)</formula>
    		</property>
    		<property name="annee" type="integer">
    			<formula>year(DATE_CALENDRIER)</formula>
    		</property>
    		<property name="mois" type="integer">
    			<formula>month(DATE_CALENDRIER)</formula>
    		</property>
    	</class>
    </hibernate-mapping>
    je suis donc passé sur cette solution (un seul mapping) sans entity-name.
    Mais ce code :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    session.saveOrUpdate(r);
    donne toujours la même exception.... pourtant j'ai bien
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    	<mapping resource="mapping/production/rebut_mapping.xml" />
    dans mon hibernate.cfg.xml, la preuve le select fonctionne toujours...
    Je suis vraiment sec d'idée là
    Si tu ne peut pas battre ton ordinateur aux echecs, essaye le kick boxing

  6. #6
    Membre à l'essai
    Inscrit en
    Février 2007
    Messages
    20
    Détails du profil
    Informations forums :
    Inscription : Février 2007
    Messages : 20
    Points : 13
    Points
    13
    Par défaut
    Salut, je remets UP ce post car j'ai le même soucis.
    C'est à dire qu'en faisant un SELECT dans ma base, le mapping se fait correctement mais lorsque je veux faire un INSERT par la méthode save(Object o) ou saveOrUpdate(Object o), j'ai une erreur similaire à savoir "Unknown Entity".

Discussions similaires

  1. Problème List avec Entity
    Par haithem.bsh dans le forum Spring
    Réponses: 1
    Dernier message: 16/06/2014, 23h01
  2. Problème démarrage avec Entity Framework
    Par heloise77u2 dans le forum Entity Framework
    Réponses: 2
    Dernier message: 06/09/2011, 17h34
  3. Problème insertion avec Entity + sql compact
    Par big_grim dans le forum C#
    Réponses: 1
    Dernier message: 03/08/2011, 16h39
  4. Problème avec le Naming Service
    Par touma dans le forum CORBA
    Réponses: 1
    Dernier message: 06/12/2006, 13h49
  5. MSXML4 - <!DOCTYPE> Problème avec <!ENTITY> exte
    Par trent94 dans le forum XML/XSL et SOAP
    Réponses: 2
    Dernier message: 11/07/2005, 17h20

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