I am using bundled JBoss Portal with JBoss AS version 2.6.2 GA.
For hibernate version I found:
<jar name="hibernate3.jar" specVersion="4.2.1.GA" specVendor="JBoss (
http://www.jboss.org/)" specTitle="JBoss" implVersion="3.2.4.sp1" implVendor="hibernate.org" implTitle="Hibernate3" implVendorID="http://www.jboss.org/" implURL="http://www.jboss.org/" sealed="false" md5Digest="8ea37c0f59a01a2ec2276454c2c58ac7"/>
I tried at Jboss forums, I searched the hibernate forums, read the two places I found PropertyAccessException in the faqs. Read the "Sessions and transactions" article, but I was unable to find the solution for the PropertyAccessException.
I am new to hibernate, so it may be me overlooking somthing. If anybody could direct me to the correct path (there are so many options its a bit overwhelming) I would be gratefull:
I tried creating and persisting EJB beans, but there where too many unknown errors, so now I'm trying to just persist a simple class with Hibernate.
But I am still unable to persist a class, because of the following exception:
Code:
org.hibernate.PropertyAccessException: IllegalArgumentException occurred calling getter of a.b.c.Cik
k.cim
org.hibernate.property.BasicPropertyAccessor$BasicGetter.get(BasicPropertyAccessor.java:171)
org.hibernate.PropertyAccessException: IllegalArgumentException occurred calling getter of a.b.c.Cik
k.cim
org.hibernate.property.BasicPropertyAccessor$BasicGetter.getForInsert(BasicPropertyAccessor.java:182
)
org.hibernate.PropertyAccessException: IllegalArgumentException occurred calling getter of a.b.c.Cik
k.cim
org.hibernate.tuple.entity.AbstractEntityTuplizer.getPropertyValuesToInsert(AbstractEntityTuplizer.j
ava:271)
org.hibernate.PropertyAccessException: IllegalArgumentException occurred calling getter of a.b.c.Cik
k.cim
....
If anyone could lend a hand, I would be happy.
I created my Hibernate mbean in my .har in the jboss-service.xml file:
Code:
</mbean>
<mbean code="org.jboss.hibernate.jmx.Hibernate"
name="jboss.har:service=Hibernate">
<attribute name="DatasourceName">java:/DefaultDS</attribute>
<attribute name="Dialect">
org.hibernate.dialect.HSQLDialect
</attribute>
<attribute name="SessionFactoryName">
java:/hibernate/SessionFactory
</attribute>
<attribute name="ScanForMappingsEnabled">true</attribute>
<attribute name="Hbm2ddlAuto">create</attribute>
</mbean>
My simple class I want to be able to persist:
Code:
package a.b.c;
import java.io.Serializable;
import javax.persistence.Id;
import javax.persistence.*;
/*@Entity
@Table(name = "cikk")*/
public class Cikk implements Serializable{
private Long id;
private String cim="Alapérték";
private String valami="Alapérték";
/** Creates a new instance of Cikk */
public Cikk() {
}
public Cikk(Long id,String cim) {
setId(id);
setCim(cim);
}
public Cikk(String cim) {
setCim(cim);
}
//@Id
public Long getId() { return id; }
public void setId(Long id) {
this.id = id;
}
public String getCim() {
return cim;
}
public void setCim(String cim) {
this.cim = cim;
}
public String getValami() {
return valami;
}
public void setValami(String valami) {
this.valami = valami;
}
}
I wanted to use annotations for persistance, but Hibernate was unable to find them, I didn't find how to use the Annotation SessionFactory or something like that. (I tried a persistance.xml with mapping class, but that didn't help)
So I created my mapping file cikk.hbm.xml instead:
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="a.b.c.Cikk" table="cikk">
<id name="id">
<generator class="native"/>
</id>
<property name="cim"/>
<property name="valami"/>
</class>
</hibernate-mapping>
The code I use to store the object:
Code:
InitialContext ctx = new InitialContext();
SessionFactory factory = (SessionFactory)ctx.lookup("java:/hibernate/SessionFactory");
Session session = factory.openSession();
Cikk c = new Cikk("Ez az elsÃÂ
ÃÂ db cikk");
Transaction tx=null;
try {
tx = session.beginTransaction();
//do some work
session.save(c);
tx.commit();
return true;
} catch (Exception e) {
if (tx!=null) tx.rollback();
response.setRenderParameter("error",e.getMessage());
throw e;
} finally {
if(session.isOpen()) session.close();
}
I do not know why I get the exception.
I tried taking properties out from the mapping file, until only the id remained, but the error persisted, except it said:
org.hibernate.PropertyAccessException: IllegalArgumentException occurred calling setter of a.b.c.Cikk.id
I must be missing something basic, can anyone help?