Reputation: 1751
I'm trying to use Hibernate with GWT and I get this error:
org.hibernate.MappingException: Unknown entity: com.asso.shared.Personne
I don't understand why I got this error! I am using annotations and the classes are genereted by Hibernate! the Personne class:
package com.asso.shared;
// Generated 26 mai 2013 23:54:30 by Hibernate Tools 3.4.0.CR1
import java.util.Date;
import java.util.HashSet;
import java.util.Set;
import javax.persistence.AttributeOverride;
import javax.persistence.AttributeOverrides;
import javax.persistence.Column;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
/**
* Personne generated by hbm2java
*/
@Entity
@Table(name = "personne", catalog = "mydb")
public class Personne implements java.io.Serializable {
private PersonneId id;
private String nom;
private String prenom;
private String photo;
private Date dnaissance;
private String civilite;
private Boolean sexe;
private String email;
private String site;
private String telPortable;
private String telDomicile;
private String telBureau;
private String adresse;
private String ville;
private String region;
private String cpostal;
private String pays;
private Date dadhesion;
private Double montantContisation;
private Double mpaye;
private Date dpayement;
private String observations;
private String mdp;
private String titre;
private Set<Doc> docs = new HashSet<Doc>(0);
private Set<Droits> droitses = new HashSet<Droits>(0);
private Set<Activite> activites = new HashSet<Activite>(0);
private Set<Groupe> groupes = new HashSet<Groupe>(0);
private Set<Courrier> courriers = new HashSet<Courrier>(0);
public Personne() {
}
public Personne(PersonneId id) {
this.id = id;
}
public Personne(PersonneId id, String nom, String prenom, String photo,
Date dnaissance, String civilite, Boolean sexe, String email,
String site, String telPortable, String telDomicile,
String telBureau, String adresse, String ville, String region,
String cpostal, String pays, Date dadhesion,
Double montantContisation, Double mpaye, Date dpayement,
String observations, String mdp, String titre, Set<Doc> docs,
Set<Droits> droitses, Set<Activite> activites, Set<Groupe> groupes,
Set<Courrier> courriers) {
this.id = id;
this.nom = nom;
this.prenom = prenom;
this.photo = photo;
this.dnaissance = dnaissance;
this.civilite = civilite;
this.sexe = sexe;
this.email = email;
this.site = site;
this.telPortable = telPortable;
this.telDomicile = telDomicile;
this.telBureau = telBureau;
this.adresse = adresse;
this.ville = ville;
this.region = region;
this.cpostal = cpostal;
this.pays = pays;
this.dadhesion = dadhesion;
this.montantContisation = montantContisation;
this.mpaye = mpaye;
this.dpayement = dpayement;
this.observations = observations;
this.mdp = mdp;
this.titre = titre;
this.docs = docs;
this.droitses = droitses;
this.activites = activites;
this.groupes = groupes;
this.courriers = courriers;
}
@EmbeddedId
@AttributeOverrides({
@AttributeOverride(name = "cin", column = @Column(name = "CIN", nullable = false)),
@AttributeOverride(name = "num", column = @Column(name = "Num", nullable = false)) })
public PersonneId getId() {
return this.id;
}
public void setId(PersonneId id) {
this.id = id;
}
@Column(name = "Nom", length = 45)
public String getNom() {
return this.nom;
}
public void setNom(String nom) {
this.nom = nom;
}
@Column(name = "Prenom", length = 45)
public String getPrenom() {
return this.prenom;
}
public void setPrenom(String prenom) {
this.prenom = prenom;
}
@Column(name = "Photo", length = 70)
public String getPhoto() {
return this.photo;
}
public void setPhoto(String photo) {
this.photo = photo;
}
@Temporal(TemporalType.DATE)
@Column(name = "DNaissance", length = 10)
public Date getDnaissance() {
return this.dnaissance;
}
public void setDnaissance(Date dnaissance) {
this.dnaissance = dnaissance;
}
@Column(name = "Civilite", length = 5)
public String getCivilite() {
return this.civilite;
}
public void setCivilite(String civilite) {
this.civilite = civilite;
}
@Column(name = "Sexe")
public Boolean getSexe() {
return this.sexe;
}
public void setSexe(Boolean sexe) {
this.sexe = sexe;
}
@Column(name = "Email", length = 45)
public String getEmail() {
return this.email;
}
public void setEmail(String email) {
this.email = email;
}
@Column(name = "Site", length = 45)
public String getSite() {
return this.site;
}
public void setSite(String site) {
this.site = site;
}
@Column(name = "TelPortable", length = 45)
public String getTelPortable() {
return this.telPortable;
}
public void setTelPortable(String telPortable) {
this.telPortable = telPortable;
}
@Column(name = "TelDomicile", length = 45)
public String getTelDomicile() {
return this.telDomicile;
}
public void setTelDomicile(String telDomicile) {
this.telDomicile = telDomicile;
}
@Column(name = "TelBureau", length = 45)
public String getTelBureau() {
return this.telBureau;
}
public void setTelBureau(String telBureau) {
this.telBureau = telBureau;
}
@Column(name = "Adresse", length = 45)
public String getAdresse() {
return this.adresse;
}
public void setAdresse(String adresse) {
this.adresse = adresse;
}
@Column(name = "Ville", length = 45)
public String getVille() {
return this.ville;
}
public void setVille(String ville) {
this.ville = ville;
}
@Column(name = "Region", length = 45)
public String getRegion() {
return this.region;
}
public void setRegion(String region) {
this.region = region;
}
@Column(name = "CPostal", length = 45)
public String getCpostal() {
return this.cpostal;
}
public void setCpostal(String cpostal) {
this.cpostal = cpostal;
}
@Column(name = "Pays", length = 45)
public String getPays() {
return this.pays;
}
public void setPays(String pays) {
this.pays = pays;
}
@Temporal(TemporalType.DATE)
@Column(name = "DAdhesion", length = 10)
public Date getDadhesion() {
return this.dadhesion;
}
public void setDadhesion(Date dadhesion) {
this.dadhesion = dadhesion;
}
@Column(name = "MontantContisation", precision = 22, scale = 0)
public Double getMontantContisation() {
return this.montantContisation;
}
public void setMontantContisation(Double montantContisation) {
this.montantContisation = montantContisation;
}
@Column(name = "MPaye", precision = 22, scale = 0)
public Double getMpaye() {
return this.mpaye;
}
public void setMpaye(Double mpaye) {
this.mpaye = mpaye;
}
@Temporal(TemporalType.DATE)
@Column(name = "DPayement", length = 10)
public Date getDpayement() {
return this.dpayement;
}
public void setDpayement(Date dpayement) {
this.dpayement = dpayement;
}
@Column(name = "Observations")
public String getObservations() {
return this.observations;
}
public void setObservations(String observations) {
this.observations = observations;
}
@Column(name = "MDP")
public String getMdp() {
return this.mdp;
}
public void setMdp(String mdp) {
this.mdp = mdp;
}
@Column(name = "Titre", length = 45)
public String getTitre() {
return this.titre;
}
public void setTitre(String titre) {
this.titre = titre;
}
@OneToMany(fetch = FetchType.LAZY, mappedBy = "personne")
public Set<Doc> getDocs() {
return this.docs;
}
public void setDocs(Set<Doc> docs) {
this.docs = docs;
}
@ManyToMany(fetch = FetchType.LAZY)
@JoinTable(name = "personne_has_droits", catalog = "mydb", joinColumns = {
@JoinColumn(name = "Personne_CIN", nullable = false, updatable = false),
@JoinColumn(name = "Personne_Num", nullable = false, updatable = false) }, inverseJoinColumns = { @JoinColumn(name = "Droits_Id", nullable = false, updatable = false) })
public Set<Droits> getDroitses() {
return this.droitses;
}
public void setDroitses(Set<Droits> droitses) {
this.droitses = droitses;
}
@ManyToMany(fetch = FetchType.LAZY)
@JoinTable(name = "activite_has_personne", catalog = "mydb", joinColumns = {
@JoinColumn(name = "Personne_CIN", nullable = false, updatable = false),
@JoinColumn(name = "Personne_Num", nullable = false, updatable = false) }, inverseJoinColumns = { @JoinColumn(name = "Activite_idActivite", nullable = false, updatable = false) })
public Set<Activite> getActivites() {
return this.activites;
}
public void setActivites(Set<Activite> activites) {
this.activites = activites;
}
@ManyToMany(fetch = FetchType.LAZY)
@JoinTable(name = "groupe_has_personne", catalog = "mydb", joinColumns = {
@JoinColumn(name = "Personne_CIN", nullable = false, updatable = false),
@JoinColumn(name = "Personne_Num", nullable = false, updatable = false) }, inverseJoinColumns = { @JoinColumn(name = "Groupe_idGroupe", nullable = false, updatable = false) })
public Set<Groupe> getGroupes() {
return this.groupes;
}
public void setGroupes(Set<Groupe> groupes) {
this.groupes = groupes;
}
@OneToMany(fetch = FetchType.LAZY, mappedBy = "personne")
public Set<Courrier> getCourriers() {
return this.courriers;
}
public void setCourriers(Set<Courrier> courriers) {
this.courriers = courriers;
}
}
the method that I'm using to persist the class Personne:
public int ajouterAdherent(Personne p) {
Session session = HibernateUtil.currentSession();
Transaction tx = null;
System.out.println("insertion");
try {
tx = session.beginTransaction();
p.toString();
session.save(p);
tx.commit();
} catch (Exception e) {
if (tx != null) {
tx.rollback();
HibernateUtil.closeSession();
e.printStackTrace();
}
HibernateUtil.closeSession();
return -1;
}
return 1;
}
this is the hibernate.cfg.xml:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost:3306/mydb</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="hibernate.show_sql">true</property>
</session-factory>
</hibernate-configuration>
Upvotes: 0
Views: 94
Reputation: 199
This problem has nothing to do with GWT.
You got: org.hibernate.MappingException because Hibernate doesn't know of your entity class. You have to add
<mapping class="com.asso.shared.Personne"/>
in hbm.xml file, or create SessionFactory
sessionFactory = new AnnotationConfiguration()
.addAnnotatedClass(...)
Read http://docs.jboss.org/hibernate/annotations/3.5/reference/en/html/ch01.html
Upvotes: 1