bonjour,
j'ai les classes suivantes :
class AbstractTypeclient :
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
| public abstract class AbstractTypeclient implements java.io.Serializable {
// Fields
private Integer idType;
private String nameType;
// Constructors
/** default constructor */
public AbstractTypeclient() {
}
/** full constructor */
public AbstractTypeclient(String nameType) {
this.nameType = nameType;
}
// Property accessors
public Integer getIdType() {
return this.idType;
}
public void setIdType(Integer idType) {
this.idType = idType;
}
public String getNameType() {
return this.nameType;
}
public void setNameType(String nameType) {
this.nameType = nameType;
}
} |
et aussi classe AbstractClient :
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 120 121 122 123 124 125
|
public abstract class AbstractClient implements java.io.Serializable {
// Fields
private Integer idClt;
private Integer typeClientIdType;
private String rsClt;
private String adressClt;
private String telClt;
private String gsmClt;
private String faxClt;
private String emailClt;
private String villeClt;
// Constructors
/** default constructor */
public AbstractClient() {
}
/** minimal constructor */
public AbstractClient(Integer typeClientIdType, String adressClt) {
this.typeClientIdType = typeClientIdType;
this.adressClt = adressClt;
}
/** full constructor */
public AbstractClient(Integer typeClientIdType, String rsClt, String adressClt, String telClt, String gsmClt, String faxClt, String emailClt, String villeClt) {
this.typeClientIdType = typeClientIdType;
this.rsClt = rsClt;
this.adressClt = adressClt;
this.telClt = telClt;
this.gsmClt = gsmClt;
this.faxClt = faxClt;
this.emailClt = emailClt;
this.villeClt = villeClt;
}
// Property accessors
public Integer getIdClt() {
return this.idClt;
}
public void setIdClt(Integer idClt) {
this.idClt = idClt;
}
public Integer getTypeClientIdType() {
return this.typeClientIdType;
}
public void setTypeClientIdType(Integer typeClientIdType) {
this.typeClientIdType = typeClientIdType;
}
public String getRsClt() {
return this.rsClt;
}
public void setRsClt(String rsClt) {
this.rsClt = rsClt;
}
public String getAdressClt() {
return this.adressClt;
}
public void setAdressClt(String adressClt) {
this.adressClt = adressClt;
}
public String getTelClt() {
return this.telClt;
}
public void setTelClt(String telClt) {
this.telClt = telClt;
}
public String getGsmClt() {
return this.gsmClt;
}
public void setGsmClt(String gsmClt) {
this.gsmClt = gsmClt;
}
public String getFaxClt() {
return this.faxClt;
}
public void setFaxClt(String faxClt) {
this.faxClt = faxClt;
}
public String getEmailClt() {
return this.emailClt;
}
public void setEmailClt(String emailClt) {
this.emailClt = emailClt;
}
public String getVilleClt() {
return this.villeClt;
}
public void setVilleClt(String villeClt) {
this.villeClt = villeClt;
}
} |
je voudrais mapper la relation :
Un Typeclient a plusieurs Client, pour cela voici ce que j'ai utilisé dans les fichiers de map :
Client.hbm.xml
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
| <?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!--
Mapping file autogenerated by MyEclipse - Hibernate Tools
-->
<hibernate-mapping>
<class name="hibern.Client" table="client" catalog="belbouir">
<id name="idClt" type="java.lang.Integer">
<column name="id_CLT" />
<generator class="increment" />
</id>
<many-to-one name="typeClientIdType" class="hibern.Typeclient" column="TypeClient_id_type" not-null="true"/>
<property name="rsClt" type="java.lang.String">
<column name="rs_clt" length="100" />
</property>
<property name="adressClt" type="java.lang.String">
<column name="adress_clt" not-null="true" />
</property>
<property name="telClt" type="java.lang.String">
<column name="tel_clt" length="20" />
</property>
<property name="gsmClt" type="java.lang.String">
<column name="gsm_clt" length="20" />
</property>
<property name="faxClt" type="java.lang.String">
<column name="fax_clt" length="20" />
</property>
<property name="emailClt" type="java.lang.String">
<column name="email_clt" length="45" />
</property>
<property name="villeClt" type="java.lang.String">
<column name="ville_clt" length="20" />
</property>
</class>
</hibernate-mapping> |
et le fichier Typeclient.hbm.xml:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
| <?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!--
Mapping file autogenerated by MyEclipse - Hibernate Tools
-->
<hibernate-mapping>
<class name="hibern.Typeclient" table="typeclient" catalog="belbouir">
<id name="idType" type="java.lang.Integer">
<column name="id_TYPE" />
<generator class="increment" />
</id>
<property name="nameType" type="java.lang.String">
<column name="name_type" length="20" />
</property>
</class>
</hibernate-mapping> |
dans une classe java j'utilise :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
|
package pack;
public class Listing {
public List cltt;
public List getCltt(){
ClientDAO dao = new ClientDAO();
List <Client> objet = dao.findAll(Client.class);
cltt=objet;
return cltt;
}
} |
Dans la page JSP, j'ai :
1 2 3 4 5 6 7 8 9
| <%@ taglib uri="http://displaytag.sf.net" prefix="display" %>
<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %>
<jsp:directive.page import="java.util.* , pack.* "/>
<html>
<body>
<jsp:useBean id="obj2" class="pack.Listing" scope="page" />
<c:forEach var="client" items="${pageScope.obj2.cltt}" >
${client.idClt} -> ${client.rsClt} <br />
</c:forEach> |
j'aimerai bine afficher au sein du foreach : -> et nameType c'est dans la classe AbstractTypeclient !
est ce que c'est possible ?
A savoir que à l'exécution de ma page JSP, j'ai les erreurs suivantes :
1 2 3
| javax.servlet.ServletException: javax.servlet.jsp.el.ELException: An error occurred while getting property "cltt" from an instance of class pack.Listing
org.hibernate.PropertyAccessException: exception setting property value with CGLIB (set hibernate.cglib.use_reflection_optimizer=false for more info) setter of hibern.Client.setTypeClientIdType |
alors que dan HQL j'exécute la requête suivante :
select idClt,rsClt,typeClientIdType.nameType from Client
, et elle me renvoie le résultat correct :
1 2 3 4
| 23 Client1 Client Fidèle
24 Client2 Client Fidèle
25 Client4 Client Passager
26 Client5 Client Passager |
Merci d'avance pour votre aide, car je suis vraiment bloqué dans cette phase
Partager