-->
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.  [ 2 posts ] 
Author Message
 Post subject: Problem with simple OneToMany case when saving
PostPosted: Wed Aug 30, 2006 10:42 am 
Newbie

Joined: Wed Aug 30, 2006 10:04 am
Posts: 2
Location: Les Sables d'Olonne, France
I am experiencing a naughty exception on a simple case :
I have an <Individu> (individual) class. Each individual can have
hold a list of <Fiche> object (a timestamp complementary information) : OneToMany unidirectional link


@OneToMany(cascade=CascadeType.ALL)
@IndexColumn(name="fiche")
@OrderBy("fiche") // => Long fiche; in Fiche.java
public List<Fiche> getFiches() {
return fiches;
}

The "org.hibernate.PropertyAccessException: IllegalArgumentException occurred while calling setter of semiosys.meteopol.wrappers.Individu.fiches" occurs when
trying to save an instance of <Individu> (see sample code below).

What am I doing wrong ?
Thank you for you help !

SOLVED :
The line
private ArrayList<Fiche> fiches = new ArrayList<Fiche>();
has been replaced by:
private List<Fiche> fiches = new ArrayList<Fiche>();
and it works now.
That's it.




Hibernate version:
hibernate-3.2.0.cr2
hibernate-annotations-3.2.0.CR1.zip
jdk 1.5.0_08

Mapping documents:
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.Enumerated;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

import org.hibernate.annotations.IndexColumn;


@Entity
public class Individu implements Serializable {

/**
*
*/
private static final long serialVersionUID = -4782256312700340494L;
public static enum Sexe { MASCULIN, FEMININ };

private Long id;
private String nomComplet;
private String nom;
private String prenom;
private Date dateDeNaissance;
private String lieuNaissance;
private Sexe sexe = Sexe.MASCULIN;
private ArrayList<Fiche> fiches = new ArrayList<Fiche>();
/**
* @param id the id to set
*/
public void setId(Long id) {
this.id = id;
}
/**
* @return the id
*/
@Id @GeneratedValue(strategy=GenerationType.AUTO)
public Long getId() {
return id;
}
/**
* @param nomComplet the nomComplet to set
*/
public void setNomComplet(String nomComplet) {
this.nomComplet = nomComplet;
}
/**
* @return the nomComplet
*/
@Basic
public String getNomComplet() {
return nomComplet;
}
/**
* @param nom the nom to set
*/
public void setNom(String nom) {
this.nom = nom;
}
/**
* @return the nom
*/
@Basic
public String getNom() {
return nom;
}
/**
* @param dateDeNaissance the dateDeNaissance to set
*/
public void setDateDeNaissance(Date dateDeNaissance) {
this.dateDeNaissance = dateDeNaissance;
}
/**
* @return the dateDeNaissance
*/
@Temporal(TemporalType.DATE)
public Date getDateDeNaissance() {
return dateDeNaissance;
}
/**
* @param lieuNaissance the lieuNaissance to set
*/
public void setLieuNaissance(String lieuNaissance) {
this.lieuNaissance = lieuNaissance;
}
/**
* @return the lieuNaissance
*/
@Basic
public String getLieuNaissance() {
return lieuNaissance;
}
/**
* @param sexe the sexe to set
*/
public void setSexe(Sexe sexe) {
this.sexe = sexe;
}
/**
* @return the sexe
*/
@Enumerated
public Sexe getSexe() {
return sexe;
}
/**
* @param fiches the fiches to set
*/
public void setFiches(ArrayList<Fiche> fiches) {
this.fiches = fiches;
}
/**
* @return the fiches
*/
@OneToMany(cascade=CascadeType.ALL)
@IndexColumn(name="fiche")
@OrderBy("fiche")
public List<Fiche> getFiches() {
return fiches;
}

}

/** Le code et les annotations de la class fiche maintenant */
@Entity
public class Fiche implements Serializable {
/**
*
*/
private static final long serialVersionUID = 4576138465945556591L;

private Long fiche;

/** Date de validité de la fiche */
private Date date;
/** Profession */
private String profession;
private boolean refFonction = false;
/** Suppléant */
private Individu suppleant = null;



/**
* @param fiche the fiche to set
*/
public void setFiche(Long fiche) {
this.fiche = fiche;
}
/**
* @return the fiche
*/
@Id @GeneratedValue(strategy=GenerationType.AUTO)
public Long getFiche() {
return fiche;
}
/**
* @param profession the profession to set
*/
public void setProfession(String profession) {
this.profession = profession;
}
/**
* @return the profession
*/
@Basic
public String getProfession() {
return profession;
}
/**
* @param suppleant the suppleant to set
*/
public void setSuppleant(Individu suppleant) {
this.suppleant = suppleant;
}
/**
* @return the suppleant
*/
@OneToOne
public Individu getSuppleant() {
return suppleant;
}
/**
* @param date the date to set
*/
public void setDate(Date date) {
this.date = date;
}
/**
* @return the date
*/
@Temporal(TemporalType.DATE)
public Date getDate() {
return date;
}
/**
* @param apparente the apparente to set
*/
public void setApparente(boolean apparente) {
this.apparente = apparente;
}
/**
* @return the apparente
*/
@Basic
public boolean isApparente() {
return apparente;
}

/**
* @param refFonction the refFonction to set
*/
public void setRefFonction(boolean refFonction) {
this.refFonction = refFonction;
}
/**
* @return the refFonction
*/
@Basic
public boolean isRefFonction() {
return refFonction;
}


}

ANT task definition
<path id="toolslib">
<path location="${lib.dir}/hibernate-tools.jar" />
<path location="${lib.dir}/hibernate3.jar" />
<path location="${lib.dir}/freemarker.jar" />
<path location="${lib.dir}/commons-logging-1.0.4.jar" />
<path location="${mysql-connector.jar}" />
<fileset dir="${lib.dir}/">
<include name="*.jar"/>
</fileset>
<pathelement location="${jars}/meteopol.jar"/>
<pathelement location="${bin}/"/>
</path>


<taskdef name="hibernatetool" classname="org.hibernate.tool.ant.HibernateToolTask" classpathref="toolslib" />


<target name="schema">
<hibernatetool destdir="${hib.dir}">
<annotationconfiguration configurationfile="${hib.dir}/hibernate.cfg.xml"/>
<classpath >
<path location="${build.dir}" />
</classpath >
<!-- list exporters here -->
<hbm2ddl create="true" update="true" export="true" outputfilename="sql.ddl" format="true" />
<hbm2doc/>
</hibernatetool>
</target>


Code between sessionFactory.openSession() and session.close():
Session session = HibernateUtil.getSession();
session.beginTransaction();
Individu ind = new Individu();
ind.setNom("Foo");
ind.setDateDeNaissance(new java.util.Date());
session.save(ind);
session.getTransaction().commit();

Full stack trace of any exception that occurs:
Exception in thread "main" org.hibernate.PropertyAccessException: IllegalArgumentException occurred while calling setter of semiosys.meteopo
l.wrappers.Individu.fiches
at org.hibernate.property.BasicPropertyAccessor$BasicSetter.set(BasicPropertyAccessor.java:104)
at org.hibernate.tuple.AbstractEntityTuplizer.setPropertyValues(AbstractEntityTuplizer.java:330)
at org.hibernate.tuple.PojoEntityTuplizer.setPropertyValues(PojoEntityTuplizer.java:191)
at org.hibernate.persister.entity.AbstractEntityPersister.setPropertyValues(AbstractEntityPersister.java:3343)
at org.hibernate.event.def.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:272)
at org.hibernate.event.def.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:180)
at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:108)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:186
)
at org.hibernate.event.def.DefaultSaveEventListener.saveWithGeneratedOrRequestedId(DefaultSaveEventListener.java:33)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:175)
at org.hibernate.event.def.DefaultSaveEventListener.performSaveOrUpdate(DefaultSaveEventListener.java:27)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:70)
at org.hibernate.impl.SessionImpl.fireSave(SessionImpl.java:537)
at org.hibernate.impl.SessionImpl.save(SessionImpl.java:525)
at org.hibernate.impl.SessionImpl.save(SessionImpl.java:521)
at semiosys.meteopol.control.Starter.main(Starter.java:28)
Caused by: java.lang.IllegalArgumentException: argument type mismatch
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.hibernate.property.BasicPropertyAccessor$BasicSetter.set(BasicPropertyAccessor.java:42)
... 15 more


Name and version of the database you are using:
MySQL 5.021 COmmunity edition


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 30, 2006 12:18 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
collection has to be an interface for ORM to provide their own implementations.
This is a good and common practice to do so even beyond ORM

_________________
Emmanuel


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.