Java JEE: recréation des entités dans BDD

Fermé
Leaffy Messages postés 55 Date d'inscription jeudi 3 novembre 2011 Statut Membre Dernière intervention 15 août 2012 - 26 déc. 2011 à 12:48
Leaffy Messages postés 55 Date d'inscription jeudi 3 novembre 2011 Statut Membre Dernière intervention 15 août 2012 - 26 déc. 2011 à 12:50
Bonjour,

J'ai 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:

@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:

@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:

@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:

@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...


A voir également:

1 réponse

Leaffy Messages postés 55 Date d'inscription jeudi 3 novembre 2011 Statut Membre Dernière intervention 15 août 2012 6
26 déc. 2011 à 12:50
et voici le persistence.xml bien évidemment:

<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://www.oracle.com/webfolder/technetwork/jsc/xml/ns/persistence/index.html" 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" />
      		
      		<property name="hibernate.connection.charSet" value="utf8"/>
      		<property name="hibernate.connection.useUnicode" value="true"/>
		</properties>
	</persistence-unit>
</persistence>
0