Hi zusammen,
ich steh auf dem Schlauch, habe folgendes Problem:
Ist Tabellen in der DB:
Table "customer":
Table "task":
Klasse Task.java:
Die Klasse Customer.java:
Zum Verständnis:
So wie es jetzt gepostet ist, werden beiden Klassen geladen und die GUI Befüllt wie erwartet.
Ihr seht da Kommentierte Join statements... ich versuche entsprechend die Richtigen informationen zusammenzustellen, habe einiges an Literatur gelesen doch leider noch keine für mich funktionierende Lösung...
Wenn ich versuche die Tabellen zusammen zu führen habe ich folgende Error Meldung in der Console:
Der funktionierende SQL Query String ist:
Wobei ich die categorie noch auslasse, muss es erst mit dem Task und Customer zum laufen kriegen.
habt ihr eine idee?
ich steh auf dem Schlauch, habe folgendes Problem:
Ist Tabellen in der DB:
Table "customer":
Code:
+----------------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+----------------+--------------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| customernumber | bigint(8) | NO | MUL | NULL | |
| company | varchar(250) | YES | | NULL | |
| salutation | int(11) | YES | MUL | NULL | |
| firstname | varchar(250) | YES | | NULL | |
| lastname | varchar(250) | YES | | NULL | |
| address | varchar(250) | YES | | NULL | |
| code | int(11) | YES | | NULL | |
| city | varchar(250) | YES | | NULL | |
| country | varchar(250) | YES | | NULL | |
| mobile | varchar(250) | YES | | NULL | |
| private | varchar(250) | YES | | NULL | |
| business | varchar(250) | YES | | NULL | |
| email | varchar(250) | YES | | NULL | |
| fullname | varchar(250) | YES | | NULL | |
| phoneBusiness | varchar(255) | YES | | NULL | |
| phonePrivate | varchar(255) | YES | | NULL | |
+----------------+--------------+------+-----+---------+----------------+
Table "task":
Code:
+-------------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------------+--------------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| tasknr | bigint(8) | YES | | NULL | |
| customer | int(11) | YES | MUL | NULL | |
| name | varchar(250) | YES | | NULL | |
| description | varchar(250) | YES | | NULL | |
| categorie | int(11) | YES | MUL | NULL | |
| done | tinyint(1) | YES | | NULL | |
| project | int(11) | YES | MUL | NULL | |
| bill | int(11) | YES | | NULL | |
| idinvoice | int(11) | YES | | NULL | |
| time | double | YES | | NULL | |
| total | double | YES | | NULL | |
| date | date | YES | | NULL | |
| dateTask | datetime | YES | | NULL | |
| fullName | varchar(255) | YES | | NULL | |
+-------------+--------------+------+-----+---------+----------------+
Klasse Task.java:
Code:
@Entity
@Table(name = "task")
public class Task {
@Id
@GeneratedValue
@Column(name = "id")
private int id;
private String fullName;
private long taskNr;
@Column(name = "name")
private String name;
private String description;
private String categorie;
private boolean done;
private boolean bill;
private double time;
private double total;
private Date dateTask;
// @JoinColumn(name = "id")
// @ManyToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
// private List<Customer> customer;
// private Customer customer;
public Task(String fullName, long taskNr, String name, String description, String categorie, Boolean done,
Boolean bill, double time, double total, Date date) {
this.fullName = fullName;
this.description = description;
this.name = name;
this.categorie = categorie;
this.done = done;
this.taskNr = taskNr;
this.bill = bill;
this.time = time;
this.total = total;
this.dateTask = date;
// this.customer = customer;
}
public Task() {
}
// @OneToOne(cascade = CascadeType.ALL)
// @JoinTable(
// name = "customer",
// joinColumns = @JoinColumn(name="id"),
// inverseJoinColumns = @JoinColumn(name="customer")
// )
//
// @Column
// @ElementCollection(targetClass = xx.xxx.models.Customer.class)
// public List<Customer> getCustomer(){
// return this.customer;
// }
//
// public void setCustomer (List<Customer> customer){
// this.customer = customer;
// }
Die Klasse Customer.java:
Code:
@Entity
@Table(name="customer")
public class Customer {
@Id
@GeneratedValue
@Column(name="id")
private int id;
private long customerNumber;
private String company;
private String salutation;
private String firstName;
private String lastName;
private String address;
private int code;
private String city;
private String country;
private String phonePrivate;
private String phoneBusiness;
private String mobile;
private String email;
@Column(name="fullname")
private String fullName;
// private List<Task> taskList;
public Customer(){
}
public Customer(long customerNumber, String company, String salutation, String firstName, String lastName, String address,
int code, String city, String country, String phonePrivate, String phoneBusiness, String mobile,
String eMail, String fullName) {
this.customerNumber = customerNumber;
this.company = company;
this.salutation = salutation;
this.firstName = firstName;
this.lastName = lastName;
this.address = address;
this.code = code;
this.city = city;
this.country = country;
this.phonePrivate = phonePrivate;
this.phoneBusiness = phoneBusiness;
this.mobile = mobile;
this.email = eMail;
this.fullName = fullName;
}
// public void setTaskList(List<Task> taskList){
// this.taskList = taskList;
// }
// @ManyToMany(cascade = CascadeType.ALL)
// @JoinTable(name = "task")
// public List<Task> getTaskList(){
// return this.taskList;
// }
So wie es jetzt gepostet ist, werden beiden Klassen geladen und die GUI Befüllt wie erwartet.
Ihr seht da Kommentierte Join statements... ich versuche entsprechend die Richtigen informationen zusammenzustellen, habe einiges an Literatur gelesen doch leider noch keine für mich funktionierende Lösung...
Wenn ich versuche die Tabellen zusammen zu führen habe ich folgende Error Meldung in der Console:
Code:
org.hibernate.AnnotationException: @OneToOne or @ManyToOne on xx.xxx.models.Task.customer references an unknown entity: java.util.List
Der funktionierende SQL Query String ist:
Code:
String query = "select task.id, task.tasknr, customer.fullname as fullname, task.name, task.description, " +
"task.done, task.project, categorie.name as categorie\n, task.bill, task.time, task.total, task.date " +
"from task\n" +
"left join categorie on task.categorie = categorie.id " +
"left join customer on task.customer = customer.id";
Wobei ich die categorie noch auslasse, muss es erst mit dem Task und Customer zum laufen kriegen.
habt ihr eine idee?