J2ee/javaee
Fermé
booloo
Messages postés
76
Date d'inscription
jeudi 21 mai 2009
Statut
Membre
Dernière intervention
26 mai 2020
-
10 janv. 2010 à 22:45
booloo Messages postés 76 Date d'inscription jeudi 21 mai 2009 Statut Membre Dernière intervention 26 mai 2020 - 13 janv. 2010 à 21:17
booloo Messages postés 76 Date d'inscription jeudi 21 mai 2009 Statut Membre Dernière intervention 26 mai 2020 - 13 janv. 2010 à 21:17
4 réponses
BadGuitarist
Messages postés
367
Date d'inscription
dimanche 12 octobre 2008
Statut
Membre
Dernière intervention
20 octobre 2013
27
11 janv. 2010 à 00:12
11 janv. 2010 à 00:12
Bonsoir Booloo,
Désolé, le compilateur a raison : tu n'as pas respecté la casse :
Ton attribut est : private String firstName;
et ton RegstrationBean devrait être (je crois) firstName
Remarque importante (et là, j'en suis sûr) :
Ton getter DOIT ETRE : getFirstName
Ton setter DOIT ETRE : setFirstName
Désolé, le compilateur a raison : tu n'as pas respecté la casse :
Ton attribut est : private String firstName;
et ton RegstrationBean devrait être (je crois) firstName
Remarque importante (et là, j'en suis sûr) :
Ton getter DOIT ETRE : getFirstName
Ton setter DOIT ETRE : setFirstName
booloo
Messages postés
76
Date d'inscription
jeudi 21 mai 2009
Statut
Membre
Dernière intervention
26 mai 2020
13 janv. 2010 à 13:45
13 janv. 2010 à 13:45
Salut, regarde mon code de RegistrationBean
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package com.ensode.jsf.managedbeans;
/**
*
* @author Od
*/
public class RegistrationBean {
/** Creates a new instance of RegistrationBean */
public RegistrationBean() {
}
private String salutation;
private String firstName;
private String lastName;
private Integer age;
private String email;
public Integer getAge() {
return age;
}
public String getEmail() {
return email;
}
public String getFirstName() {
return firstName;
}
public String getLastName() {
return lastName;
}
public String getSalutation() {
return salutation;
}
public void setAge(Integer age) {
this.age = age;
}
public void setEmail(String email) {
this.email = email;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public void setSalutation(String salutation) {
this.salutation = salutation;
}
La meme erreur persiste.
Merci.
}
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package com.ensode.jsf.managedbeans;
/**
*
* @author Od
*/
public class RegistrationBean {
/** Creates a new instance of RegistrationBean */
public RegistrationBean() {
}
private String salutation;
private String firstName;
private String lastName;
private Integer age;
private String email;
public Integer getAge() {
return age;
}
public String getEmail() {
return email;
}
public String getFirstName() {
return firstName;
}
public String getLastName() {
return lastName;
}
public String getSalutation() {
return salutation;
}
public void setAge(Integer age) {
this.age = age;
}
public void setEmail(String email) {
this.email = email;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public void setSalutation(String salutation) {
this.salutation = salutation;
}
La meme erreur persiste.
Merci.
}
BadGuitarist
Messages postés
367
Date d'inscription
dimanche 12 octobre 2008
Statut
Membre
Dernière intervention
20 octobre 2013
27
13 janv. 2010 à 17:35
13 janv. 2010 à 17:35
Bonjour,
Et peux-tu envoyer aussi le code qui appelle cette registrationBean car le problème serait une non concordance entre la définition de la classe et son appel.
Concernant la définition de la classe, je ne vois pas de problème , en effet.
Et peux-tu envoyer aussi le code qui appelle cette registrationBean car le problème serait une non concordance entre la définition de la classe et son appel.
Concernant la définition de la classe, je ne vois pas de problème , en effet.
booloo
Messages postés
76
Date d'inscription
jeudi 21 mai 2009
Statut
Membre
Dernière intervention
26 mai 2020
13 janv. 2010 à 21:17
13 janv. 2010 à 21:17
Bonsoir BadGuistarist, voici ce code:
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package org.book;
import java.io.Serializable;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedQuery;
/**
*
* @author Od
*/
@Entity
@NamedQuery(name="findAllBooks", query="SELECT b FROM Book b")
public class Book implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
@Column(nullable=false)
private String title;
private Float price;
@Column(length=2000)
private String description;
private String isbn;
private Integer nbOfPage;
private Boolean illustration;
public Book(Long id, String title, Float price, String description, String isbn, Integer nbOfPage, Boolean illustration) {
this.id = id;
this.title = title;
this.price = price;
this.description = description;
this.isbn = isbn;
this.nbOfPage = nbOfPage;
this.illustration = illustration;
}
public String getDescription() {
return description;
}
public Boolean getIllustration() {
return illustration;
}
public String getIsbn() {
return isbn;
}
public Integer getNbOfPage() {
return nbOfPage;
}
public Float getPrice() {
return price;
}
public static long getSerialVersionUID() {
return serialVersionUID;
}
public String getTitle() {
return title;
}
public void setDescription(String description) {
this.description = description;
}
public void setIllustration(Boolean illustration) {
this.illustration = illustration;
}
public void setIsbn(String isbn) {
this.isbn = isbn;
}
public void setNbOfPage(Integer nbOfPage) {
this.nbOfPage = nbOfPage;
}
public void setPrice(Float price) {
this.price = price;
}
public void setTitle(String title) {
this.title = title;
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
@Override
public int hashCode() {
int hash = 0;
hash += (id != null ? id.hashCode() : 0);
return hash;
}
@Override
public boolean equals(Object object) {
// TODO: Warning - this method won't work in the case the id fields are not set
if (!(object instanceof Book)) {
return false;
}
Book other = (Book) object;
if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
return false;
}
return true;
}
@Override
public String toString() {
return "org.book.Book[id=" + id + "]";
}
}
Voici les deux session Beans qui doivent traiter l'entity precedent:
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package org.session;
import javax.ejb.Local;
/**
*
* @author Od
*/
@Local
public interface BookEJBLocal {
public java.util.List<java.awt.print.Book> findBooks();
public java.awt.print.Book createBook(java.awt.print.Book book);
}
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package org.session;
import java.awt.print.Book;
import java.util.List;
import javax.ejb.Stateless;
import javax.management.Query;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
/**
*
* @author Od
*/
@Stateless
public class BookEJBBean implements BookEJBLocal {
@PersistenceContext(unitName="Book-ejbPU")
private EntityManager em;
public List<Book> findBooks(){
Query query=(Query) em.createNamedQuery("findAllBooks");
return query.getResultList();
}
public Book createBook(Book book){
em.persist(book);
return book;
}
// Add business logic below. (Right-click in editor and choose
// "Insert Code > Add Business Method" or "Web Service > Add Operation")
}
Le probleme est que , la ligne: return query.getResultList();
Affiche une erreur
Aider moi s'il vous plait.
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package org.book;
import java.io.Serializable;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedQuery;
/**
*
* @author Od
*/
@Entity
@NamedQuery(name="findAllBooks", query="SELECT b FROM Book b")
public class Book implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
@Column(nullable=false)
private String title;
private Float price;
@Column(length=2000)
private String description;
private String isbn;
private Integer nbOfPage;
private Boolean illustration;
public Book(Long id, String title, Float price, String description, String isbn, Integer nbOfPage, Boolean illustration) {
this.id = id;
this.title = title;
this.price = price;
this.description = description;
this.isbn = isbn;
this.nbOfPage = nbOfPage;
this.illustration = illustration;
}
public String getDescription() {
return description;
}
public Boolean getIllustration() {
return illustration;
}
public String getIsbn() {
return isbn;
}
public Integer getNbOfPage() {
return nbOfPage;
}
public Float getPrice() {
return price;
}
public static long getSerialVersionUID() {
return serialVersionUID;
}
public String getTitle() {
return title;
}
public void setDescription(String description) {
this.description = description;
}
public void setIllustration(Boolean illustration) {
this.illustration = illustration;
}
public void setIsbn(String isbn) {
this.isbn = isbn;
}
public void setNbOfPage(Integer nbOfPage) {
this.nbOfPage = nbOfPage;
}
public void setPrice(Float price) {
this.price = price;
}
public void setTitle(String title) {
this.title = title;
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
@Override
public int hashCode() {
int hash = 0;
hash += (id != null ? id.hashCode() : 0);
return hash;
}
@Override
public boolean equals(Object object) {
// TODO: Warning - this method won't work in the case the id fields are not set
if (!(object instanceof Book)) {
return false;
}
Book other = (Book) object;
if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
return false;
}
return true;
}
@Override
public String toString() {
return "org.book.Book[id=" + id + "]";
}
}
Voici les deux session Beans qui doivent traiter l'entity precedent:
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package org.session;
import javax.ejb.Local;
/**
*
* @author Od
*/
@Local
public interface BookEJBLocal {
public java.util.List<java.awt.print.Book> findBooks();
public java.awt.print.Book createBook(java.awt.print.Book book);
}
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package org.session;
import java.awt.print.Book;
import java.util.List;
import javax.ejb.Stateless;
import javax.management.Query;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
/**
*
* @author Od
*/
@Stateless
public class BookEJBBean implements BookEJBLocal {
@PersistenceContext(unitName="Book-ejbPU")
private EntityManager em;
public List<Book> findBooks(){
Query query=(Query) em.createNamedQuery("findAllBooks");
return query.getResultList();
}
public Book createBook(Book book){
em.persist(book);
return book;
}
// Add business logic below. (Right-click in editor and choose
// "Insert Code > Add Business Method" or "Web Service > Add Operation")
}
Le probleme est que , la ligne: return query.getResultList();
Affiche une erreur
Aider moi s'il vous plait.