-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 
Author Message
 Post subject: Class cast Exception for only one entity
PostPosted: Fri Feb 06, 2009 1:19 pm 
Newbie

Joined: Fri Sep 26, 2008 4:45 am
Posts: 17
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


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 09, 2009 10:53 am 
Senior
Senior

Joined: Tue Aug 01, 2006 9:24 pm
Posts: 120
can you post the exception?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 09, 2009 12:54 pm 
Newbie

Joined: Tue Jan 06, 2009 5:03 am
Posts: 7
Please paste the stack trace .That will help


Top
 Profile  
 
 Post subject: Re: Class cast Exception for only one entity
PostPosted: Thu Sep 24, 2009 12:13 pm 
Newbie

Joined: Tue Jan 06, 2009 5:03 am
Posts: 7
Paste Stack trace . it will help to find out the problem.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.