Bonjour je travaille avec eclipse la version ganymede et le serveur jboss 4.2.1 lorsque j'essai j'utiliser les requetes JPQL pour l'affichage des donnèes de ma base j'obtiens ceci:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
entityBeans.Customer@f70f8e
voici mon customer bean


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
package entityBeans;
 
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import java.io.Serializable;
 
 
@Entity
public class Customer implements Serializable {
   private int idcustomer;
   private String firstname;
   private String lastname;
   private String email;
   private String adresse;
   private String zipCode;
   private String city;
   private int phone;
   private String password;
 
   @Id
   @GeneratedValue(strategy = GenerationType.AUTO)
public int getIdcustomer() {
	return idcustomer;
}
public void setIdcustomer(int idcustomer) {
	this.idcustomer = idcustomer;
}
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 getEmail() {
	return email;
}
public void setEmail(String email) {
	this.email = email;
}
public String getAdresse() {
	return adresse;
}
public void setAdresse(String adresse) {
	this.adresse = adresse;
}
public String getZipCode() {
	return zipCode;
}
public void setZipCode(String zipCode) {
	this.zipCode = zipCode;
}
public String getCity() {
	return city;
}
public void setCity(String city) {
	this.city = city;
}
public int getPhone(){
	return phone;
}
public void setPhone(int phone){
	this.phone=phone;
}
public String getPassword(){
	return password;
}
public void setPassword(String password){
	this.password=password;
}
 
}

interface :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
 
package sessionBeans;
import java.util.List;
import entityBeans.Customer;
import javax.ejb.Remote;
 
 
@Remote
public interface GestionContactRemote {
  public String coucouContact(String nomContact);
  public void addContact(String first, String last, String mail, String add,String zip, String city, int phone,String password);
  //public String findCustomerById(int idcustomer);
  public List<Customer>getCustomer();
}
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
package sessionBeans;
 
 
 
import javax.ejb.Remote;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;
 
import java.util.List;
import entityBeans.Customer;
 
@Stateless(name="GestionContactRemote")
@Remote(GestionContactRemote.class)
public class GestionContactBean implements GestionContactRemote{
	@PersistenceContext
	EntityManager em;
 
 
	public String coucouContact(String nomContact) {
 
		return "Coucou,"+nomContact;
	}
 
 
 
 
	public void addContact(String first, String last, String mail, String add,String zip, String city, int phone,String password) {
		Customer c = new Customer();
		c.setFirstname(first);
		c.setLastname(last);
		c.setEmail(mail);
		c.setAdresse(add);
		c.setZipCode(zip);
		c.setCity(city);
		c.setPhone(phone);
		c.setPassword(password);
		em.persist(c);
 
 
	}
 
 
 
 
 
	public List<Customer> getCustomer() {
 
		return em.createQuery("SELECT c FROM Customer c").getResultList();
 
 
 
	}
 
 
 
 
	//public String findCustomerById(int idcustomer) {
		//Customer c = em.find(Customer.class,idcustomer);
		//return c.getLastname()+","+c.getFirstname();
	//}
 
 
 
 
 
 
 
}

et la fonction main que j'appele dans l'application cliente:



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
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import sessionBeans.GestionContactRemote;
import entityBeans.Customer;
import java.util.List;
import java.util.Iterator;
public class Main {
	public static void main(String[] args) {
		try{
			  Context context = new InitialContext();
			  GestionContactRemote beanRemote = (GestionContactRemote)context.lookup("GestionContactRemote/remote");
			  System.out.println(beanRemote.coucouContact("Mon Premier Client EjB3 "));
			  beanRemote.addContact("jkl","lomp","pom","htyfg","kiluy","lopjg",9,"opli");
			  System.out.println("Le nom du contact a ètè ajoutè dans la base:");
			  //+beanRemote.findCustomerById(0)
			  List<Customer> customers = beanRemote.getCustomer();
			  for (Iterator<Customer> iter= customers.iterator();iter.hasNext();){
            	  Customer mycust = (Customer)iter.next();
            	  System.out.println(mycust);
              }
		}
		catch(NamingException e){
			e.printStackTrace();
		}
	}
 
	/* (non-Java-doc)
	 * @see java.lang.Object#Object()
	 */
	public Main() {
		super();
	}
 
}