Hi,
I'm facing a strange behavior for only one entity I've developped
When I'm trying to save this kind of entity an exception is throwed : Class cast exception
Here is my entity :
Code:
@Entity
public class AuteurPlans implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "auteurId")
private long id;
@Column(name = "auteurNom", length = 200, nullable = true)
private String nom;
@Column(name = "auteurPrenom", length = 40, nullable = true)
private String prenom;
@Column(name = "noTel", length = 40, nullable = true)
private String noTel;
@Column(name = "noFax", length = 40, nullable = true)
private String noFax;
@Column(name = "email", length = 40, nullable = true)
private String email;
@ManyToOne(fetch = FetchType.EAGER, cascade = CascadeType.ALL, optional = true)
private Adresse adresse;
@Column(name = "autoriseNome", length = 40, nullable = true)
private String nomPersonneAutorisee;
@Column(name = "autoriseNum")
private int numeroRegistre;
@ManyToMany(fetch = FetchType.EAGER)
@Cascade ((org.hibernate.annotations.CascadeType.SAVE_UPDATE))
private Set<Adresse> autresAdresse;
/**
* Constructor
*/
public AuteurPlans() {
if (this.adresse == null) {
this.adresse = new Adresse();
}
autresAdresse = new HashSet<Adresse>();
}
/**
* Gets the autres adresses
*
* @return Set<Adresse> returns the Set of autres adresses
*/
public Set<Adresse> getAutresAdresse() {
return autresAdresse;
}
/**
* Set the Set of autres adresses
*
* @param autresAdresse
* The Collection to set
*/
public void setAutresAdresse(Set<Adresse> autresAdresse) {
this.autresAdresse = autresAdresse;
}
/**
* Gets the id
*
* @return long returns the id
*/
public long getId() {
return id;
}
/**
* Sets the id
*
* @param id
* the id to set
*/
public void setId(long id) {
this.id = id;
}
/**
* Gets the nom
*
* @return String returns the nom
*/
public String getNom() {
return nom;
}
/**
* Gets the prenom
*
* @return String returns the prenom
*/
public String getPrenom() {
return prenom;
}
/**
* Sets the prenom
*
* @param prenom
* The prenom to set
*/
public void setPrenom(String prenom) {
this.prenom = prenom;
}
/**
*
* Sets the nom
*
* @param nom
* the nom to set
*/
public void setNom(String nom) {
this.nom = nom;
}
/**
*
* Gets the no telephone
*
* @return String returns the noTel
*/
public String getNoTel() {
return noTel;
}
/**
* Set no telephone to set
*
* @param noTel
* the noTel to set
*/
public void setNoTel(String noTel) {
this.noTel = noTel;
}
/**
* Gets the no fax
*
* @return String returns the noFax
*
*/
public String getNoFax() {
return noFax;
}
/**
* Sets the no fax
*
* @param noFax
* the noFax to set
*/
public void setNoFax(String noFax) {
this.noFax = noFax;
}
/**
* Gets the email
*
* @return String returns the email
*/
public String getEmail() {
return email;
}
/**
* Sets the email
*
* @param email
* the email to set
*/
public void setEmail(String email) {
this.email = email;
}
/**
* Gets the adresse
*
* @return Adresse returns the adresse
*/
public Adresse getAdresse() {
return adresse;
}
/**
* Sets the adresse
*
* @param adresse
* the adresse to set
*/
public void setAdresse(Adresse adresse) {
this.adresse = adresse;
}
/**
* Gets the nom personne autorisee
*
* @return String returns the nomPersonneAutorisee
*/
public String getNomPersonneAutorisee() {
return nomPersonneAutorisee;
}
/**
* Sets the nom personne autorisee
*
* @param nomPersonneAutorisee
* the nomPersonneAutorisee to set
*/
public void setNomPersonneAutorisee(String nomPersonneAutorisee) {
this.nomPersonneAutorisee = nomPersonneAutorisee;
}
/**
*
* Gets the numero registre
*
* @return int returns the numeroRegistre
*/
public int getNumeroRegistre() {
return numeroRegistre;
}
/**
* @param numeroRegistre the numeroRegistre to set
*/
public void setNumeroRegistre(int numeroRegistre) {
this.numeroRegistre = numeroRegistre;
}
/*
* (non-Javadoc)
*
* @see java.lang.Object#equals(java.lang.Object)
*/
@Override
public boolean equals(Object obj) {
return EqualsBuilder.reflectionEquals(this, obj);
}
/*
* (non-Javadoc)
*
* @see java.lang.Object#equals(java.lang.Object)
*/
@Override
public int hashCode() {
return HashCodeBuilder.reflectionHashCode(this);
}
/*
* (non-Javadoc)
*
* @see java.lang.Object#equals(java.lang.Object)
*/
@Override
public String toString() {
return ToStringBuilder.reflectionToString(this);
}
}
And my dao save code
Code:
public AuteurPlans save(AuteurPlans auteur) throws Exception{
try{
Session session = getSession();
session.getSessionFactory().openSession();
Transaction tx = session.beginTransaction();
auteur = (AuteurPlans) session.save(auteur);
tx.commit();
session.close();
return auteur;
}catch (Exception ex) {
LOG.error("SAVE OF AUTEUR PLAN FAILED : " + ex);
throw ex;
}
}
I've developped several entities and all are working. I heard it's not a good idea to use primitive type
But I want to understand why it's work for all other entities except this one