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 :

Persister un Set d'objets


Sujet :

Hibernate Java

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre confirmé
    Profil pro
    Inscrit en
    Octobre 2010
    Messages
    57
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Octobre 2010
    Messages : 57
    Par défaut Persister un Set d'objets
    Bonjour,

    J'utilise actuellement hibernate 4.3.5 final pour la persistance d'objets en base, j'ai une classe Team qui contient un Set de type Player et une classe Player contenant un objet de type Team. Le tout avec une relation de type one-to-many (Team 1 -- * Player) or j'aurais aimé persister une instance Team qui contient un Set d'objets de type Player mais malgré mes nombreuses tentatives je bloque


    voici le code :

    Player.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
    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
     
     
    package foot;
     
    public class Player {
     
    	private int Player_Id;
    	private Team team;
    	private String nom;
    	private String prenom;
     
     
    	public Player(int player_Id, String nom, String prenom, Team team) {
    		super();
    		Player_Id = player_Id;
    		this.nom = nom;
    		this.prenom = prenom;
    		//this.team=team;
    	}
     
    	public Player(int player_Id, String nom, String prenom) {
    		super();
    		Player_Id = player_Id;
    		this.nom = nom;
    		this.prenom = prenom;		
    	}
     
    	public Player() {
    		super();
    	}
     
     
    	public int getPlayer_Id() {
    		return Player_Id;
    	}
     
    	public void setPlayer_Id(int player_Id) {
    		Player_Id = player_Id;
    	}
     
    	public String getNom() {
    		return nom;
    	}
     
    	public void setNom(String nom) {
    		this.nom = nom;
    	}
     
    	public String getPrenom() {
    		return prenom;
    	}
     
    	public void setPrenom(String prenom) {
    		this.prenom = prenom;
    	}
     
    	public Team getTeam() {
    		return team;
    	}
     
    	public void setTeam(Team team) {
    		this.team = team;
    	}
    }

    Team.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
    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
     
     
    package foot;
     
    import java.util.HashSet;
    import java.util.Set;
     
     
    public class Team {
     
    	private int idteam;
    	private String nom;
    	private Set<Player> players;
    	private Coach coach;
     
    	public Team (){
    		super();
    	}
     
    	public Team(int team_Id, String nom,Coach coach, Set<Player> players) {
    		super();
    		idteam = team_Id;
    		this.nom = nom;
    		this.players = players;
    		this.coach = coach;
    	}
     
    	public Team(int team_Id, String nom,Coach coach) {
    		super();
    		idteam = team_Id;
    		this.nom = nom;
    		this.players = players;
    		this.coach = coach;
    	}
     
     
    	public int getidteam() {
    		return idteam;
    	}
     
    	public void setidteam(int team_Id) {
    		idteam = team_Id;
    	}
     
    	public String getNom() {
    		return nom;
    	}
     
     
    	public void setNom(String nom) {
    		this.nom = nom;
    	}
     
    	public Set<Player> getPlayers() {
    		return players;
    		}
     
    	public void setPlayers(Set<Player> players) {
    		this.players = players;
    	}
     
    	public Coach getCoach() {
    		return coach;
    	}
     
    	public void setCoach(Coach coach) {
    		this.coach = coach;
    	}
     
    }

    Player.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
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
     
     
    <?xml version="1.0" encoding="UTF-8"?>
     
    <!DOCTYPE hibernate-mapping PUBLIC
    "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
    "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
     
    <hibernate-mapping >
    <class name="foot.Player" table="PLAYER">
    <id name="Player_Id" column="ID_PLAYER" >
    <generator class="native"/>
    </id>
     
    <property name="nom">
    <column name="NOM" />
    </property>
    <property name="prenom"> <column name="PRENOM" />
    </property>
     
     
     <many-to-one name="team" class="foot.Team"  column="ID_TEAM" not-null="true"></many-to-one> 
     
    </class>
    </hibernate-mapping>
    Team.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
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
     
    <?xml version="1.0" encoding="UTF-8"?>
     
    <!DOCTYPE hibernate-mapping PUBLIC
    "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
    "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
     
    <hibernate-mapping>
    <class name="foot.Team" table="TEAM">
    <id name="idteam" column="ID_TEAM" >
    <generator class="native"/>
    </id>
     
    <property name="nom">
    <column name="NOM" />
    </property>
     
    <many-to-one name="coach" class="foot.Coach" column="ID_COACH"  cascade="all" not-null="true"/>
     
    <set name="players" cascade="all" inverse="true" >
    <key column = "ID_TEAM" />
    <one-to-many class="foot.Player"/>
    </set>
    </class>
    </hibernate-mapping>
    Et le code effectuant la persistance des données
    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
     
     
      Session session = HibernateUtil.getSessionFactory().openSession(); 
     
    	    Transaction tx = null; 
    	    try { 
    	      tx = session.beginTransaction(); 
     
    	      Coach coach = new Coach(1,"galles","charles");
    	      Set<Player> players = new HashSet<Player>();
    	      players.add(new Player(1,"anelka","nicolas"));
    	      players.add(new Player(2,"henry","thierry"));
    	      players.add(new Player(3,"zinedine","zidane"));
    	      players.add(new Player(4,"barthez","fabien"));
     
    	      Team team1 = new Team (1,"france",coach);
    	      team1.setPlayers(players);
    	      session.merge(team1);
     
    	      session.flush() ;
    	      tx.commit();
    ...
    voici ce que j'obtiens lors de l'exécution du code :

    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
     
     
    Hibernate: create table COACH (ID_COACH integer not null auto_increment, NOM varchar(255), PRENOM varchar(255), primary key (ID_COACH))
    Hibernate: create table PLAYER (ID_PLAYER integer not null auto_increment, NOM varchar(255), PRENOM varchar(255), ID_TEAM integer not null, primary key (ID_PLAYER))
    Hibernate: create table PRODUCT (ID_PRODUIT bigint not null, NOM varchar(255), DESCRIPTION varchar(255), PRIX double precision, primary key (ID_PRODUIT))
    Hibernate: create table TEAM (ID_TEAM integer not null auto_increment, NOM varchar(255), ID_COACH integer not null, primary key (ID_TEAM))
    Hibernate: alter table PLAYER add constraint FK_cy0c8kjv1lt1e3p8xc9fvlvho foreign key (ID_TEAM) references TEAM (ID_TEAM)
    Hibernate: alter table TEAM add constraint FK_l9anvcxm58gxtu644cvk0cmbb foreign key (ID_COACH) references COACH (ID_COACH)
    Hibernate: select team0_.ID_TEAM as ID_TEAM1_3_2_, team0_.NOM as NOM2_3_2_, team0_.ID_COACH as ID_COACH3_3_2_, coach1_.ID_COACH as ID_COACH1_0_0_, coach1_.NOM as NOM2_0_0_, coach1_.PRENOM as PRENOM3_0_0_, players2_.ID_TEAM as ID_TEAM4_3_4_, players2_.ID_PLAYER as ID_PLAYE1_1_4_, players2_.ID_PLAYER as ID_PLAYE1_1_1_, players2_.NOM as NOM2_1_1_, players2_.PRENOM as PRENOM3_1_1_, players2_.ID_TEAM as ID_TEAM4_1_1_ from TEAM team0_ inner join COACH coach1_ on team0_.ID_COACH=coach1_.ID_COACH left outer join PLAYER players2_ on team0_.ID_TEAM=players2_.ID_TEAM where team0_.ID_TEAM=?
    Hibernate: select coach0_.ID_COACH as ID_COACH1_0_0_, coach0_.NOM as NOM2_0_0_, coach0_.PRENOM as PRENOM3_0_0_ from COACH coach0_ where coach0_.ID_COACH=?
    Hibernate: insert into COACH (NOM, PRENOM) values (?, ?)
    Hibernate: insert into TEAM (NOM, ID_COACH) values (?, ?)
    Hibernate: select player0_.ID_PLAYER as ID_PLAYE1_1_0_, player0_.NOM as NOM2_1_0_, player0_.PRENOM as PRENOM3_1_0_, player0_.ID_TEAM as ID_TEAM4_1_0_ from PLAYER player0_ where player0_.ID_PLAYER=?
    non inserer
    Exception in thread "main" org.hibernate.PropertyValueException: not-null property references a null or transient value : foot.Player.team

    Merci d'avance.

  2. #2
    Membre averti
    Homme Profil pro
    Étudiant
    Inscrit en
    Février 2013
    Messages
    12
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Belgique

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Février 2013
    Messages : 12
    Par défaut
    Je suis pas sûr mais je pense que tu dois utiliser une balise 'one-to-many' dans 'team.hbm.xm' plutôt qu'une balise 'many-to-one'.

    Cf : http://www.mkyong.com/hibernate/hibe...nship-example/

  3. #3
    Membre confirmé
    Profil pro
    Inscrit en
    Octobre 2010
    Messages
    57
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Octobre 2010
    Messages : 57
    Par défaut
    salut,

    merci de ta contribution, en fait j'utilise justement une balise one-to-many dans mon team.hbm.xml J'ai tenté de persister mon set cette fois-ci en pensant à bien ajouter un objet team à chaque player mais j'ai toujours une erreur.


    player.java contenant la redéfinition des méthodes equals et hashcode :


    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
     
     
     
    	@Override
    	public boolean equals(Object o) {
     
    		  System.out.println("methode equals executé");
    		 if (this == o) return true;
    	        if (o == null || this.getClass() != o.getClass()) return false;
     
    	        final Player person = (Player) o;
     
    	        if(person.getPlayer_Id()==this.Player_Id)return true;
    	        if (!person.getNom().equals(nom)) return false;
    	        if (!person.getPrenom().equals(prenom))return false;
     
    			return true ;
    	}
     
    	@Override
    	public int hashCode() {
     
    		 int result = nom.hashCode();
    	        result = 31 * result + prenom.hashCode();
    	        return result;
    	}
    voici le main avec les nouvelles modifications
    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
     
    		Coach coach = new Coach(1, "galles", "charles");
    			Team team1 = new Team(1, "france", coach);
     
    			Set<Player> players = new HashSet<Player>();
    			Player pl1 = new Player(1, "anelka", "nicolas");
    			pl1.setTeam(team1);
     
    			players.add(pl1);
    			pl1 = new Player(2, "henry", "thierry");
    			pl1.setTeam(team1);
    			players.add(pl1);
    			pl1 = new Player(3, "zinedine", "zidane");
    			pl1.setTeam(team1);
    			players.add(pl1);
    			pl1 = new Player(4, "barthez", "fabien");
    			pl1.setTeam(team1);
    			players.add(pl1);
     
    			team1.setPlayers(players);
    			System.out.println("sauvegarde equipe");
    			session.merge(team1);
    voici le resultat :


    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
     
     
    Hibernate: alter table PLAYER drop foreign key FK_cy0c8kjv1lt1e3p8xc9fvlvho
    Hibernate: alter table TEAM drop foreign key FK_l9anvcxm58gxtu644cvk0cmbb
    Hibernate: drop table if exists COACH
    Hibernate: drop table if exists PLAYER
    Hibernate: drop table if exists PRODUCT
    Hibernate: drop table if exists TEAM
    Hibernate: create table COACH (ID_COACH integer not null auto_increment, NOM varchar(255), PRENOM varchar(255), primary key (ID_COACH))
    Hibernate: create table PLAYER (ID_PLAYER integer not null auto_increment, NOM varchar(255), PRENOM varchar(255), ID_TEAM integer, primary key (ID_PLAYER))
    Hibernate: create table PRODUCT (ID_PRODUIT bigint not null, NOM varchar(255), DESCRIPTION varchar(255), PRIX double precision, primary key (ID_PRODUIT))
    Hibernate: create table TEAM (ID_TEAM integer not null auto_increment, NOM varchar(255), ID_COACH integer not null, primary key (ID_TEAM))
    Hibernate: alter table PLAYER add constraint FK_cy0c8kjv1lt1e3p8xc9fvlvho foreign key (ID_TEAM) references TEAM (ID_TEAM)
    Hibernate: alter table TEAM add constraint FK_l9anvcxm58gxtu644cvk0cmbb foreign key (ID_COACH) references COACH (ID_COACH)
    sauvegarde equipe
    Hibernate: select team0_.ID_TEAM as ID_TEAM1_3_2_, team0_.NOM as NOM2_3_2_, team0_.ID_COACH as ID_COACH3_3_2_, coach1_.ID_COACH as ID_COACH1_0_0_, coach1_.NOM as NOM2_0_0_, coach1_.PRENOM as PRENOM3_0_0_, players2_.ID_TEAM as ID_TEAM4_3_4_, players2_.ID_PLAYER as ID_PLAYE1_1_4_, players2_.ID_PLAYER as ID_PLAYE1_1_1_, players2_.NOM as NOM2_1_1_, players2_.PRENOM as PRENOM3_1_1_, players2_.ID_TEAM as ID_TEAM4_1_1_ from TEAM team0_ inner join COACH coach1_ on team0_.ID_COACH=coach1_.ID_COACH left outer join PLAYER players2_ on team0_.ID_TEAM=players2_.ID_TEAM where team0_.ID_TEAM=?
    Hibernate: select coach0_.ID_COACH as ID_COACH1_0_0_, coach0_.NOM as NOM2_0_0_, coach0_.PRENOM as PRENOM3_0_0_ from COACH coach0_ where coach0_.ID_COACH=?
    Hibernate: insert into COACH (NOM, PRENOM) values (?, ?)
    Hibernate: insert into TEAM (NOM, ID_COACH) values (?, ?)
    Hibernate: select player0_.ID_PLAYER as ID_PLAYE1_1_0_, player0_.NOM as NOM2_1_0_, player0_.PRENOM as PRENOM3_1_0_, player0_.ID_TEAM as ID_TEAM4_1_0_ from PLAYER player0_ where player0_.ID_PLAYER=?
    Hibernate: insert into PLAYER (NOM, PRENOM, ID_TEAM) values (?, ?, ?)
    Hibernate: select player0_.ID_PLAYER as ID_PLAYE1_1_0_, player0_.NOM as NOM2_1_0_, player0_.PRENOM as PRENOM3_1_0_, player0_.ID_TEAM as ID_TEAM4_1_0_ from PLAYER player0_ where player0_.ID_PLAYER=?
    Hibernate: insert into PLAYER (NOM, PRENOM, ID_TEAM) values (?, ?, ?)
    non inserer
    Exception in thread "main" java.lang.IllegalStateException: Error occurred while storing entity [ henry thierry |]. An entity copy [foot.Player#2] was already assigned to a different entity [ barthez fabien |].


    Je tiens à préciser que cela fonctionne si j'utilise la valeur assigned (génération manuelle de l'id) pour la création de la clé mais pas avec "native". J'ai également redéfinit les méthodes equals et hashcode mais rien n'y fait.

  4. #4
    Expert éminent
    Avatar de tchize_
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Avril 2007
    Messages
    25 482
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 46
    Localisation : Belgique

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Avril 2007
    Messages : 25 482
    Par défaut
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    Exception in thread "main" org.hibernate.PropertyValueException: not-null property references a null or transient value : foot.Player.team
    Dans tous tes players que tu crée, tu n'a jamais défini leur propriété "team", hors hibernate en a besoin. Hibernate se charge de persister les données. Mais si tu lui dit que tu as une relation bidirectionnelle team <-> Player, il est de ta responsabilité que cette relation soit correct: team référence player et player doit référencer team.

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    Exception in thread "main" java.lang.IllegalStateException: Error occurred while storing entity [ henry thierry |]. An entity copy [foot.Player#2] was already assigned to a different entity [ barthez fabien |].
    Si tu joue avec session.merge (pourquoi faire un merge sur un new team???), le merge doit avoir lieu avant toute modification:


    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
     
     
    			Team team1 = new Team(1, "france", coach);
    team1 = session.merge(team1);

  5. #5
    Modérateur
    Avatar de OButterlin
    Homme Profil pro
    Inscrit en
    Novembre 2006
    Messages
    7 313
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Novembre 2006
    Messages : 7 313
    Billets dans le blog
    1
    Par défaut
    Citation Envoyé par fats1 Voir le message
    Je tiens à préciser que cela fonctionne si j'utilise la valeur assigned (génération manuelle de l'id) pour la création de la clé mais pas avec "native". J'ai également redéfinit les méthodes equals et hashcode mais rien n'y fait.
    Justement, quand tu utilises un auto-incrément, il ne faut pas assigner de valeur à l'ID, tu le laisses à NULL.
    N'oubliez pas de consulter les FAQ Java et les cours et tutoriels Java

  6. #6
    Membre confirmé
    Profil pro
    Inscrit en
    Octobre 2010
    Messages
    57
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Octobre 2010
    Messages : 57
    Par défaut
    Bonjour,


    merci pour vos réponses, j'ai placé mon merge sur le new Team et cela ne fonctionne toujours pas, en fait j'ai une erreur qui m'indique que les id en base n'existe pas et pour cause hibernate ne fait pas de save/update mais un update directement
    d'où l'erreur, mais la question est de savoir pourquoi, cela va faire une semaine que je suis dessus et je n'arrive toujours pas à trouver une solution à mon problème.

    voici le code du main modifié :



    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
     
     
    	Coach coach = new Coach(1, "galles", "charles");
    			Team team1 = new Team(1, "france", coach);
                            team1 = (Team) session.merge(team1); // je rends l'objet team1 persistent
    			Set<Player> players = new HashSet<Player>();
    			Player pl1 = new Player(1, "anelka", "nicolas");
    			pl1.setTeam(team1);
     
    			players.add(pl1);
    			pl1 = new Player(2, "henry", "thierry");
    			pl1.setTeam(team1);
    			players.add(pl1);
    			pl1 = new Player(3, "zinedine", "zidane");
    			pl1.setTeam(team1);
    			players.add(pl1);
    			pl1 = new Player(4, "barthez", "fabien");
    			pl1.setTeam(team1);
    			players.add(pl1);
     
    			team1.setPlayers(players);
    			// session.merge(team1);

    la sortie console :

    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
     
     
    Hibernate: alter table PLAYER drop foreign key FK_cy0c8kjv1lt1e3p8xc9fvlvho
    Hibernate: alter table TEAM drop foreign key FK_l9anvcxm58gxtu644cvk0cmbb
    Hibernate: drop table if exists COACH
    Hibernate: drop table if exists PLAYER
    Hibernate: drop table if exists PRODUCT
    Hibernate: drop table if exists TEAM
    Hibernate: create table COACH (ID_COACH integer not null auto_increment, NOM varchar(255), PRENOM varchar(255), primary key (ID_COACH))
    Hibernate: create table PLAYER (ID_PLAYER integer not null auto_increment, NOM varchar(255), PRENOM varchar(255), ID_TEAM integer, primary key (ID_PLAYER))
    Hibernate: create table PRODUCT (ID_PRODUIT bigint not null, NOM varchar(255), DESCRIPTION varchar(255), PRIX double precision, primary key (ID_PRODUIT))
    Hibernate: create table TEAM (ID_TEAM integer not null auto_increment, NOM varchar(255), ID_COACH integer not null, primary key (ID_TEAM))
    Hibernate: alter table PLAYER add constraint FK_cy0c8kjv1lt1e3p8xc9fvlvho foreign key (ID_TEAM) references TEAM (ID_TEAM)
    Hibernate: alter table TEAM add constraint FK_l9anvcxm58gxtu644cvk0cmbb foreign key (ID_COACH) references COACH (ID_COACH)
    Hibernate: select team0_.ID_TEAM as ID_TEAM1_3_2_, team0_.NOM as NOM2_3_2_, team0_.ID_COACH as ID_COACH3_3_2_, coach1_.ID_COACH as ID_COACH1_0_0_, coach1_.NOM as NOM2_0_0_, coach1_.PRENOM as PRENOM3_0_0_, players2_.ID_TEAM as ID_TEAM4_3_4_, players2_.ID_PLAYER as ID_PLAYE1_1_4_, players2_.ID_PLAYER as ID_PLAYE1_1_1_, players2_.NOM as NOM2_1_1_, players2_.PRENOM as PRENOM3_1_1_, players2_.ID_TEAM as ID_TEAM4_1_1_ from TEAM team0_ inner join COACH coach1_ on team0_.ID_COACH=coach1_.ID_COACH left outer join PLAYER players2_ on team0_.ID_TEAM=players2_.ID_TEAM where team0_.ID_TEAM=?
    Hibernate: select coach0_.ID_COACH as ID_COACH1_0_0_, coach0_.NOM as NOM2_0_0_, coach0_.PRENOM as PRENOM3_0_0_ from COACH coach0_ where coach0_.ID_COACH=?
    Hibernate: insert into COACH (NOM, PRENOM) values (?, ?)
    Hibernate: insert into TEAM (NOM, ID_COACH) values (?, ?)
     affichage equipe : [ zinedine zidane |,  barthez fabien |,  henry thierry |,  anelka nicolas |]
    Hibernate: update PLAYER set NOM=?, PRENOM=?, ID_TEAM=? where ID_PLAYER=?
    non inserer
    Exception in thread "main" org.hibernate.StaleStateException: Batch update returned unexpected row count from update [0]; actual row count: 0; expected: 1
    	at org.hibernate.jdbc.Expectations$BasicExpectation.checkBatched(Expectations.java:81)
    	at org.hibernate.jdbc.Expectations$BasicExpectation.verifyOutcome(Expectations.java:73)
    	at org.hibernate.engine.jdbc.batch.internal.NonBatchingBatch.addToBatch(NonBatchingBatch.java:63)
    	at org.hibernate.persister.entity.AbstractEntityPersister.update(AbstractEntityPersister.java:3281)
    	at org.hibernate.persister.entity.AbstractEntityPersister.updateOrInsert(AbstractEntityPersister.java:3183)
    	at org.hibernate.persister.entity.AbstractEntityPersister.update(AbstractEntityPersister.java:3525)
    	at org.hibernate.action.internal.EntityUpdateAction.execute(EntityUpdateAction.java:159)
    	at org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:463)
    	at org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:349)
    	at org.hibernate.event.internal.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:350)
    	at org.hibernate.event.internal.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:56)
    	at org.hibernate.internal.SessionImpl.flush(SessionImpl.java:1222)
    	at dao.Test.main(Test.java:113)

  7. #7
    Membre confirmé
    Profil pro
    Inscrit en
    Octobre 2010
    Messages
    57
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Octobre 2010
    Messages : 57
    Par défaut
    J'ai l'impression que quoi que je fasse il y a une erreur, ne serait-ce pas tout simplement dû à une erreur de conception ou à la préférence, par hibernate, d'un coté de la relation pour l'exécution
    des opérations ?? J'ai lu le livre hibernate 3.0 d' Anthony Patricio mais il ne nous éclaire pas sur le sujet.

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Persistance des settings utilisateurs
    Par Kropernic dans le forum VB.NET
    Réponses: 3
    Dernier message: 29/05/2015, 10h32
  2. Réponses: 15
    Dernier message: 10/03/2014, 19h40
  3. Persistance des objets : comment ?
    Par SteelBox dans le forum C++
    Réponses: 1
    Dernier message: 28/11/2005, 21h47
  4. [Info]Créer un objet persistent
    Par seb55555 dans le forum JDBC
    Réponses: 5
    Dernier message: 22/02/2005, 16h53
  5. [Struts][DynaActionForm et persistance des objets]
    Par jcos dans le forum Struts 1
    Réponses: 4
    Dernier message: 22/12/2004, 09h15

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