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.  [ 3 posts ] 
Author Message
 Post subject: many-to-one problem... IllegalArgumentException on getter
PostPosted: Fri Jun 29, 2007 12:23 am 
Newbie

Joined: Mon May 14, 2007 1:57 am
Posts: 12
Hi, I'm newby to Hibernate... I've read different tutorials and got up and running the examples but got problems when implementing on my own :S
I got an horrible:

Code:
Exception in thread "main" org.hibernate.PropertyAccessException: IllegalArgumentException occurred calling getter of com.enyel.hiphop.persistent.Alumno.matricula


Does any one have an idea what that means?
My db is about a "mini-forum":
- Tema: topic's class
- Mensaje: class for a topic's messages
- Alumno: class for author's data
Hibernate version: 3

Mapping documents:
Alumno.hbm.xml
Code:
      <class name="Alumno" table="Alumno">
        <id name="matricula" column="MATRICULA" type="long" unsaved-value="null">
         <generator class="assigned"/>
       </id>
        <property name="nombre" column="NOMBRE" type="string" length="20"/>
      </class>


Tema.hbm.xml
Code:
    <class name="Tema" table="Tema">
        <id name="id" column="TEMA_ID" type="long" unsaved-value="null">
          <generator class="native"/>
       </id>
     
       <many-to-one name="autorID" column="MATRICULA" class="Alumno" not-null="true"/>
        <property name="titulo" column="TITULO" type="string" length="255"/>
        <property name="texto" column="TEXTO" type="text"/>
       <bag name="mensajes" table="Mensaje" cascade="all" lazy="false">
          <key column="TEMA_ID" not-null="true"/>
          <one-to-many class="Mensaje" />
       </bag>
      </class>


Mensaje.hbm.xml
Code:
      <class name="Mensaje" table="Mensaje">
        <id name="id" column="MENSAJE_ID" type="long" unsaved-value="null">
          <generator class="native"/>
       </id>
     
        <property name="texto" column="TEXTO" type="text"/>
      </class>


Tema.java
Code:
    public class Tema {
       private Long id;
       private Long autorID;
       private Alumno autor;
       private String titulo;
       private String texto;
       private List mensajes;
       
       public Tema(){ }
     
       public Long getId() { return this.id; }
       public Long getAutorID() { return this.autorID; }
       public Alumno getAutor() { return this.autor; }
       public String getTitulo() { return this.titulo; }
       public String getTexto() { return this.texto; }
       public List getMensajes() { return this.mensajes; }
     
       private void setId(Long id) { this.id = id; }
       public void setAutorID(Long autorID) { this.autorID = autorID; }
       public void setAutor(Alumno autor) { this.autor = autor; }
       public void setTitulo(String titulo) { this.titulo = titulo; }
       public void setTexto(String texto) { this.texto = texto; }
       public void setMensajes(List mensajes) { this.mensajes = mensajes; }
    }


Mensaje.java
Code:
    public class Mensaje {
       private Long id;
       private Long temaID;
       private String texto;
       
       public Mensaje(){ }
     
       public Long getId() { return this.id; }
       public Long getTemaID() { return this.temaID; }
       public String getTexto() { return this.texto; }
     
       private void setId(Long id) { this.id = id; }
       public void setTemaID(Long temaID) { this.temaID = temaID; }
       public void setTexto(String texto) { this.texto = texto; }
    }


Alumno.java
Code:
    public class Alumno {
       //propiedades
       private Long matricula;
       private String nombre;
       
       public Alumno() { }
       
       public Long getMatricula() { return this.matricula; }
       public String getNombre() { return this.nombre; }
     
       public void setMatricula(Long matricula) { this.matricula = matricula; }
       public void setNombre(String nombre) { this.nombre = nombre; }
    }


Code between sessionFactory.openSession() and session.close():
Code:
            Session session = SingletonSessionFactory.getSessionFactory().getCurrentSession();
            session.beginTransaction();
     
            Alumno a1 = new Alumno();
            a1.setMatricula(458793L);
            a1.setNombre("Pepe el Toro");
            session.save(a1);
     
            Tema tema = new Tema();
            tema.setAutor(a1);
            tema.setAutorID(a1.getMatricula());
            tema.setTitulo("Main topic example");
            tema.setTexto("this is the text for the main topic example");
            session.save(tema);
     
            session.getTransaction().commit();     
            SingletonSessionFactory.getSessionFactory().close();


Full stack trace of any exception that occurs:
Code:
Exception in thread "main" org.hibernate.PropertyAccessException: IllegalArgumentException occurred calling getter of com.enyel.hiphop.persistent.Alumno.matricula
   at org.hibernate.property.BasicPropertyAccessor$BasicGetter.get(BasicPropertyAccessor.java:171)
   at org.hibernate.tuple.entity.AbstractEntityTuplizer.getIdentifier(AbstractEntityTuplizer.java:183)
   at org.hibernate.persister.entity.AbstractEntityPersister.getIdentifier(AbstractEntityPersister.java:3589)
   at org.hibernate.persister.entity.AbstractEntityPersister.isTransient(AbstractEntityPersister.java:3305)
   at org.hibernate.engine.ForeignKeys.isTransient(ForeignKeys.java:181)
   at org.hibernate.engine.ForeignKeys$Nullifier.isNullifiable(ForeignKeys.java:137)
   at org.hibernate.engine.ForeignKeys$Nullifier.nullifyTransientReferences(ForeignKeys.java:69)
   at org.hibernate.engine.ForeignKeys$Nullifier.nullifyTransientReferences(ForeignKeys.java:47)
   at org.hibernate.event.def.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:288)
   at org.hibernate.event.def.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:181)
   at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:107)
   at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:187)
   at org.hibernate.event.def.DefaultSaveEventListener.saveWithGeneratedOrRequestedId(DefaultSaveEventListener.java:33)
   at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:172)
   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:535)
   at org.hibernate.impl.SessionImpl.save(SessionImpl.java:523)
   at org.hibernate.impl.SessionImpl.save(SessionImpl.java:519)
   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.context.ThreadLocalSessionContext$TransactionProtectionWrapper.invoke(ThreadLocalSessionContext.java:301)
   at $Proxy0.save(Unknown Source)
   at com.enyel.hiphop.test.Test.main(Test.java:50)
Caused by: java.lang.IllegalArgumentException: object is not an instance of declaring class
   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$BasicGetter.get(BasicPropertyAccessor.java:145)
   ... 25 more


Name and version of the database you are using: MySQL


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 29, 2007 1:04 am 
Regular
Regular

Joined: Mon Apr 02, 2007 3:54 am
Posts: 67
Location: Hyderabad
In many-to-one mapping specify name="autor" and try

Thanks,
Gopal
[Please rate, If helpful]


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 29, 2007 12:59 pm 
Newbie

Joined: Mon May 14, 2007 1:57 am
Posts: 12
Yeah, that's true!!! The error was there, on the many-to-one mapping...
I wrote name="autorID", but as you said it should be name="autor"

Thx a lot! I just rated as helpful :D


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