Création des entités dans la base de données
Bonjour j'ai de nouveau un petit problème, lors de mon précédent projet j'ai réussi à générer mes colonnes dans ma base de données après avoir défini mes entités, j'ai apporté quelques modifications à mon code, j'ai recompilé le tout mais malheureusement les colonnes ne se génèrent plus...Si quelqu'un voit quelque chose qui cloche dans mon code qui empecherait la création des colonnes dans la base...:
classe Student:
Code:
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
| @Entity
@Table(name = "STUDENT")
public class Student implements Serializable{
private static final long serialVersionUID = 1L;
@Id @GeneratedValue
private Long id;
private Long campusId;
@ManyToOne
@JoinColumn(name="speaker_fk")
private Speaker speaker;
@ManyToOne
@JoinColumn(name="intervention_fk")
private Intervention intervention;
public Student() {
}
public Student(Long id) {
this.id = id;
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public Speaker getSpeaker() {
return speaker;
}
public void setSpeaker(Speaker speaker) {
this.speaker = speaker;
}
public Intervention getIntervention() {
return intervention;
}
public void setIntervention(Intervention intervention) {
this.intervention = intervention;
}
public Long getCampusId() {
return campusId;
}
public void setCampusId(Long campusId) {
this.campusId = campusId;
}
//fonctions student:
} |
classe Speaker:
Code:
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
| @Entity
@Table(name = "SPEAKER")
public class Speaker implements Serializable{//utilisation flux
private static final long serialVersionUID = 1L;
@Id @GeneratedValue
private Long id;
// @Column(unique=true, nullable=false)
private String firstName;
// @Column(unique=true, nullable=false)
private String lastName;
// @Column(unique=true, nullable=false)
private String mail;
// @Column(unique=true, nullable=false)
private String password;
@OneToMany(mappedBy="speaker")
private List<Student> students;
@OneToMany(mappedBy="speaker")
private List<Intervention> interventions;
public Speaker() {
}
public Speaker(String firstName, String lastName, String mail,
String password) {
this.firstName = firstName;
this.lastName = lastName;
this.mail = mail;
this.password = password;
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public String getMail() {
return mail;
}
public void setMail(String mail) {
this.mail = mail;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public List<Student> getStudents() {
return students;
}
public void setStudents(List<Student> students) {
this.students = students;
}
public List<Intervention> getInterventions() {
return interventions;
}
public void setInterventions(List<Intervention> interventions) {
this.interventions = interventions;
}
//fonctions speakers
} |
classe Intervention:
Code:
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 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157
| @Entity
@Table(name = "INTERVENTION")
public class Intervention implements Serializable{
private static final long serialVersionUID = 1L;
@Id @GeneratedValue
private Long id;
// @Column(unique=true, nullable=false)
private String subject;
// @Column(nullable=false)
private Date beginDate;
// @Column(nullable=false)
private Date endDate;
// @Column(nullable=false)
private String status;
// @Column(nullable=false)
private String description;
// @Column(nullable=false)
private Double evalNumber;
// @Column(nullable=false)
private Double avg_mark_spk;
// @Column(nullable=false)
private Double avg_mark_slides;
// @Column(nullable=false)
private Double globalAverage;
@ManyToOne
@JoinColumn(name = "speaker_fk")
private Speaker speaker;
@ManyToOne
@JoinColumn(name = "campus_fk")
private Campus campus;
//getters and setters & constructor
public Intervention(String subject, Date beginDate, Date endDate,
String status, String description) {
this.subject = subject;
this.beginDate = beginDate;
this.endDate = endDate;
this.status = status;
this.description = description;
}
public Intervention() {
}
public String getSubject() {
return subject;
}
public void setSubject(String subject) {
this.subject = subject;
}
public Date getBeginDate() {
return beginDate;
}
public void setBeginDate(Date beginDate) {
this.beginDate = beginDate;
}
public Date getEndDate() {
return endDate;
}
public void setEndDate(Date endDate) {
this.endDate = endDate;
}
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public Double getEvalNumber() {
return evalNumber;
}
public void setEvalNumber(Double evalNumber) {
this.evalNumber = evalNumber;
}
public Double getAvg_mark_spk() {
return avg_mark_spk;
}
public void setAvg_mark_spk(Double avg_mark_spk) {
this.avg_mark_spk = avg_mark_spk;
}
public Double getAvg_mark_slides() {
return avg_mark_slides;
}
public void setAvg_mark_slides(Double avg_mark_slides) {
this.avg_mark_slides = avg_mark_slides;
}
public Double getGlobalAverage() {
return globalAverage;
}
public void setGlobalAverage(Double globalAverage) {
this.globalAverage = globalAverage;
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public Speaker getSpeaker() {
return speaker;
}
public void setSpeaker(Speaker speaker) {
this.speaker = speaker;
}
public Campus getCampus() {
return campus;
}
public void setCampus(Campus campus) {
this.campus = campus;
}
} |
classe Campus:
Code:
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
| @Entity
@Table(name = "CAMPUS")
public class Campus implements Serializable{
private static final long serialVersionUID = 1L;
@Id @GeneratedValue
private Long id;
// @Column(unique=true, nullable=false)
private String name;
@ManyToMany
@JoinTable(name = "intervention")
private List<Intervention> interventions;
@ManyToOne
@JoinColumn(name = "student_fk")
private Student student;
public Campus(String name) {
this.name = name;
}
public Campus() {
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public List<Intervention> getInterventions() {
return interventions;
}
public void setInterventions(List<Intervention> interventions) {
this.interventions = interventions;
}
public Student getStudent() {
return student;
}
public void setStudent(Student student) {
this.student = student;
}
} |
Je ne sais pas si je m'y prends bien question relation des différentes entités: un Speaker est un professeur qui peut avoir 1 ou plusieurs Interventions, par Campus (ville/localité). Chaque intervenant (Speaker) peut avoir plusieurs Student et plusieurs Campus peuvent avoir plusieurs Interventions.
En espérant que cela est suffisamment clair...Voici quand même mon fichier persistence.xml, je précise que je débute en java et que mes anciennes entités généraient bien mes colonnes avant modification...
persistence.xml:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
| <?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence" version="2.0">
<persistence-unit name="NoteTonSTA-PU" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<properties>
<property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver" />
<property name="javax.persistence.jdbc.user" value="root" />
<property name="javax.persistence.jdbc.password" value="" />
<property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/notetonsta" />
<property name="hibernate.hbm2ddl.auto" value="create" />
<!-- ou update -->
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5Dialect" />
</properties>
</persistence-unit>
</persistence> |