Ich versuche, im Winterschlaf beizutreten, und ich benutze Struts2. Ich arbeite mit Hibernate mit Annotations. Jetzt bin ich nicht in der Lage, Join zwischen zwei Tabellen durchzuführen. Meine erste Tabelle ist "studentprojects", die pid und email enthalten. Zweite Tabelle ist "initialprojectdetials", die pid, Name, Beschreibung enthält ... ähnlich einigen anderen fields.I muss das bekommen Daten der zweiten Tabelle durch Durchführen von Join-Around-PID der ersten Tabelle. Dazu ist mit dieser Abfrage:Hibernate mit Annotaion
String hql="from InitialProjectDTO I join I.projectId S where I.projectId=:id";
Query query=session.createQuery(hql);
query.setParameter("id", id);
mail =query.list();
wo Mail ist die Arraylist von InitialProjectDTO. Und mein InitialProjectDTO ist:
package edu.pma.dto;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.OneToMany;
import javax.persistence.Table;
@Entity
@Table(name="initialprojectdetail")
public class InitialProjectDTO {
@Id
@Column(name="projectId")
@OneToMany(cascade=CascadeType.ALL)
@JoinTable(name="studentprojects",[email protected](name="projectId"))
int projectId;
@Column(name="name")
String name;
@Column(name="description")
String description;
@Column(name="technology")
String technology;
@Column(name="guide")
String guide;
@Column(name="duration")
int duration;
@Column(name="status")
String status;
@Column(name="report")
String report;
public String getReport() {
return report;
}
public void setReport(String report) {
this.report = report;
}
public int getProjectId() {
return projectId;
}
public void setProjectId(int projectId) {
this.projectId = projectId;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public String getTechnology() {
return technology;
}
public void setTechnology(String technology) {
this.technology = technology;
}
public String getGuide() {
return guide;
}
public void setGuide(String guide) {
this.guide = guide;
}
public int getDuration() {
return duration;
}
public void setDuration(int duration) {
this.duration = duration;
}
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status;
}
}
mein SudentProjectDTO ist:
package edu.pma.dto;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
@Entity
@Table(name="studentprojects")
public class StudentProjectDTO {
public int getProjectId() {
return projectId;
}
public void setProjectId(int projectId) {
this.projectId = projectId;
}
@Id
@Column(name="email")
String email;
@Column(name="projectId")
int projectId;
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
}
Dies ist der Fehler, die ich erhalte:
Illegal attempt to map a non collection as a @OneToMany, @ManyToMany or @CollectionOfElements: edu.pma.dto.InitialProjectDTO.projectId
Method "execute" failed for object [email protected]
File: org/hibernate/cfg/annotations/CollectionBinder.java
Vielen Dank für Ihre Antwort sein. Aber es hat nicht für mich funktioniert. Ich benutze Annotation deshalb kann ich kein zusätzliches Feld in meiner DTO-Klasse hinzufügen außer denen, die die Teil-DB-Tabelle sind. Deshalb gibt es mir den Fehler, die Sesdion-Fabrik nicht zu bauen. –