-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: probleme d'ecriture bdd mapping <composite-element
PostPosted: Tue Apr 24, 2007 6:34 am 
Newbie

Joined: Tue Apr 24, 2007 6:11 am
Posts: 4
Bonjour,
Je suis debutant, j'utilise Hibernate3 et je voudrai lié 2 tables: Plan et Obstacle, j'ai ecrit le fichier de mapping de la classe plan, Pour la classe obstacle j'ai codé que la classe en java, il me genere les 2 table mais n'effectue pas d'ecriture dans la bdd:

fichier de mapping de la classe PLAN::::::


<class name="Plan" table="PLAN">
<id name="id" column="ID" unsaved-value="0">
<generator class="native"></generator>
</id>
<property name="nbX" column="NOMBRE_LIGNE" type="int" not-null="true" />
<property name="nbY" column="NOMBRE_COLONNE" type="int" not-null="true" />
<set name="obstacles" table="OBSTACLES">
<key column="ID" />
<composite-element class="Obstacle">
<property name="x" column="ABSCISSE" type="int" not-null="true" />
<property name="y" column="COORDONNEE" type="int" not-null="true" />
</composite-element>
</set>
</class>


La classe Plan::::::

public class Plan {
private int id;
private int nbX;
private int nbY;
private Set<Obstacle> obstacles;

public Plan() {
obstacles=new HashSet<Obstacle>();
}
public Plan(int nbX, int nbY) {
this();
this.nbX = nbX;
this.nbY = nbY;
}
public Set<Obstacle> getObstacles() {
return obstacles;
}
public void setObstacles(Set<Obstacle> obstacles) {
this.obstacles = obstacles;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public int getNbX() {
return nbX;
}
public void setNbX(int nbX) {
this.nbX = nbX;
}
public int getNbY() {
return nbY;
}
public void setNbY(int nbY) {
this.nbY = nbY;
}
}


la classe obstacle::::::

public class Obstacle {
private int x;
private int y;

public Obstacle() {

}
public Obstacle(int x, int y) {
this.x = x;
this.y = y;
}

public int getX() {
return x;
}
public void setX(int x) {
this.x = x;
}
public int getY() {
return y;
}
public void setY(int y) {
this.y = y;
}
}

test:::::::

Plan plan=new Plan(nbl,nbc);

Obstacle obst=new Obstacle(5,6);
Obstacle obst1=new Obstacle(8,6);
Obstacle obst2=new Obstacle(3,2);

plan.getObstacles().add(obst);
plan.getObstacles().add(obst1);
plan.getObstacles().add(obst2);

session.save(obst);
session.save(obst1);
session.save(obst2);

session.save(plan);
trans.commit();


Merci d'avance pour votre aide


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 24, 2007 3:19 pm 
Newbie

Joined: Tue Apr 24, 2007 6:11 am
Posts: 4
puisque personne ne me reponds alors je vais me repondre car j'ai trouvé:

au lieu de faire

Plan plan=new Plan(i,n);
Obstacle obs=new Obstacle(x,y);
plan.getObstacles().add(obs);
session.save(obs);
session.save(plan);
trans.commit;


il faut faire directement:


plan.getObstacles().add(new Obstacle(x,y);
session.save(plan);


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.