bonjour;
j'essaie de faire un jointure entre deux table contact et personne selon l'attribut firstname mais cela ne fonctionnait pas:

voila ma classe contact
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
 
package com.labosun.cj.ejb3.entity;
 
import java.io.Serializable;
 
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.OneToOne;
 
/**
* Entity Bean Contact
* @author Cyril
*
*/
@Entity // Annotation indiquant que la classe est un entity bean
public class Contact implements Serializable{
 
private int id;
 
private String firstname;
 
private String lastname;
 
private String address;
 
private int zipCode;
 
private String city;
 
private String phone;
 
private String mobile;
 
private Personne personne;
 
@OneToOne
@JoinColumn(referencedColumnName="FIRSTNAME")
 
public Personne getPersonne() {
return personne;
}
 
public void setPersonne(Personne personne) {
this.personne = personne;
}
 
public Contact() {
}
 
@Id // tag d�finissant la cl� primaire
@GeneratedValue(strategy=GenerationType.AUTO) // tag indiquant que la cl� est auto g�n�r�e
public int getId() {
return id;
}
 
public void setId(int id) {
this.id = id;
}
 
public String getAddress() {
return address;
}
 
public void setAddress(String address) {
this.address = address;
}
 
public String getCity() {
return city;
}
 
public void setCity(String city) {
this.city = city;
}
 
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 getMobile() {
return mobile;
}
 
public void setMobile(String mobile) {
this.mobile = mobile;
}
 
public String getPhone() {
return phone;
}
 
public void setPhone(String phone) {
this.phone = phone;
}
 
public int getZipCode() {
return zipCode;
}
 
public void setZipCode(int zipCode) {
this.zipCode = zipCode;
}
 
}
et voila ma classe personne
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
 
package com.labosun.cj.ejb3.entity;
import java.io.Serializable;
 
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.OneToOne;
 
 
/**
* Entity Bean Contact
* @author Cyril
*
*/
@Entity // Annotation indiquant que la classe est un entity bean
public class Personne implements Serializable{
 
	private int id;
	private String firstname;
	private String lastname;
	private Contact contact;
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
 
public int getId() {
return id;
}
 
public void setId(int id) {
this.id = id;
}
@OneToOne(mappedBy="personne")
public Contact getContact() {
	return contact;
	}
	public void setContact(Contact contact) {
	this.contact = contact;
	}
	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;
		}
}
et le requete
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
 
em.createQuery("SELECT contact.lastname FROM Contact AS contact JOIN contact.personne AS personne").getResultList();