Hibernate throw IllegalArgumentException when i want to save country object.
Hibernate version:
I am using Jboss version 4.0.4.GA Application server
Hibernate3.
Mapping documents:
public class Country implements PersistenceData {
private int countryId;
private String name;
private String phoneCode;
public int getCountryId() {
return countryId;
}
public void setCountryId(int countryId) {
this.countryId = countryId;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getPhoneCode() {
return phoneCode;
}
public void setPhoneCode(String phoneCode) {
this.phoneCode = phoneCode;
}
}
<class
name="com.pix.bean.Country"
table="Country" >
<id
name="countryId"
column="countryId"
type="int" >
<generator class="native" />
</id>
<property name="phoneCode" type="java.lang.String" length="11" />
<property name="name" type="java.lang.String" length="32" />
</class>
Code between sessionFactory.openSession() and session.close():
Session session = ConnFactory.getSessionFactory().openSession();
Transaction tx =session.beginTransaction();
try {
if(type == ActionType.Insert)
{
session.save(form);
} else
if(type == ActionType.Update)
{
session.update(form);
} else
if(type == ActionType.Delete)
{
session.delete(form);
}
if(type == ActionType.AddOrUpdate)
{
session.saveOrUpdate(form);
}
session.getTransaction().commit();
} catch(HibernateException ex) {
tx.rollback();
throw new PersistenceException(ex);
}
finally
{
try
{
if (session != null) {session.close();}
}
catch (Exception e)
{
System.out.println(e);
}
Full stack trace of any exception that occurs:
11:36:12,311 ERROR [STDERR] com.pix.manager.ManagerException: com.pix.persistent
.model.PersistenceException: org.hibernate.PropertyAccessException: IllegalArgum
entException occurred calling getter of com.pix.bean.Country.phoneCode
11:36:12,311 ERROR [STDERR] at com.pix.manager.PersistanceManager.doProcess(
PersistanceManager.java:45)
11:36:12,311 ERROR [STDERR] at com.pix.manager.PersistanceManager.insert(Per
sistanceManager.java:17)
11:36:12,311 ERROR [STDERR] at com.pix.web.actions.TestAction.add(TestAction
.java:24)
11:36:12,311 ERROR [STDERR] at sun.reflect.NativeMethodAccessorImpl.invoke0(
Native Method)
11:36:12,311 ERROR [STDERR] at sun.reflect.NativeMethodAccessorImpl.invoke(N
ativeMethodAccessorImpl.java:39)
11:36:12,311 ERROR [STDERR] at sun.reflect.DelegatingMethodAccessorImpl.invo
ke(DelegatingMethodAccessorImpl.java:25)
11:36:12,311 ERROR [STDERR] at java.lang.reflect.Method.invoke(Method.java:5
85)
11:36:12,311 ERROR [STDERR] at org.apache.struts.actions.DispatchAction.disp
atchMethod(DispatchAction.java:274)
11:36:12,311 ERROR [STDERR] at org.apache.struts.actions.DispatchAction.exec
ute(DispatchAction.java:194)
11:36:12,311 ERROR [STDERR] at org.apache.struts.action.RequestProcessor.pro
cessActionPerform(RequestProcessor.java:419)
11:36:12,311 ERROR [STDERR] at org.apache.struts.action.RequestProcessor.pro
cess(RequestProcessor.java:224)
11:36:12,311 ERROR [STDERR] at org.apache.struts.action.ActionServlet.proces
s(ActionServlet.java:1194)
11:36:12,311 ERROR [STDERR] at org.apache.struts.action.ActionServlet.doGet(
ActionServlet.java:414)
11:36:12,311 ERROR [STDERR] at javax.servlet.http.HttpServlet.service(HttpSe
rvlet.java:697)
11:36:12,311 ERROR [STDERR] at javax.servlet.http.HttpServlet.service(HttpSe
rvlet.java:810)
11:36:12,311 ERROR [STDERR] at org.apache.catalina.core.ApplicationFilterCha
in.internalDoFilter(ApplicationFilterChain.java:252)
11:36:12,311 ERROR [STDERR] at org.apache.catalina.core.ApplicationFilterCha
in.doFilter(ApplicationFilterChain.java:173)
11:36:12,311 ERROR [STDERR] at org.jboss.web.tomcat.filters.ReplyHeaderFilte
r.doFilter(ReplyHeaderFilter.java:96)
11:36:12,311 ERROR [STDERR] at org.apache.catalina.core.ApplicationFilterCha
in.internalDoFilter(ApplicationFilterChain.java:202)
11:36:12,311 ERROR [STDERR] at org.apache.catalina.core.ApplicationFilterCha
in.doFilter(ApplicationFilterChain.java:173)
11:36:12,311 ERROR [STDERR] at org.apache.catalina.core.StandardWrapperValve
.invoke(StandardWrapperValve.java:213)
11:36:12,311 ERROR [STDERR] at org.apache.catalina.core.StandardContextValve
.invoke(StandardContextValve.java:178)
11:36:12,311 ERROR [STDERR] at org.jboss.web.tomcat.security.SecurityAssocia
tionValve.invoke(SecurityAssociationValve.java:175)
11:36:12,311 ERROR [STDERR] at org.jboss.web.tomcat.security.JaccContextValv
e.invoke(JaccContextValve.java:74)
11:36:12,311 ERROR [STDERR] at org.apache.catalina.core.StandardHostValve.in
voke(StandardHostValve.java:126)
11:36:12,311 ERROR [STDERR] at org.apache.catalina.valves.ErrorReportValve.i
nvoke(ErrorReportValve.java:105)
11:36:12,311 ERROR [STDERR] at org.apache.catalina.core.StandardEngineValve.
invoke(StandardEngineValve.java:107)
11:36:12,311 ERROR [STDERR] at org.apache.catalina.connector.CoyoteAdapter.s
ervice(CoyoteAdapter.java:148)
11:36:12,311 ERROR [STDERR] at org.apache.coyote.http11.Http11Processor.proc
ess(Http11Processor.java:869)
11:36:12,311 ERROR [STDERR] at org.apache.coyote.http11.Http11BaseProtocol$H
ttp11ConnectionHandler.processConnection(Http11BaseProtocol.java:664)
11:36:12,311 ERROR [STDERR] at org.apache.tomcat.util.net.PoolTcpEndpoint.pr
ocessSocket(PoolTcpEndpoint.java:527)
11:36:12,311 ERROR [STDERR] at org.apache.tomcat.util.net.MasterSlaveWorkerT
hread.run(MasterSlaveWorkerThread.java:112)
11:36:12,311 ERROR [STDERR] at java.lang.Thread.run(Thread.java:595)
11:36:12,311 ERROR [STDERR] Caused by: com.pix.persistent.model.PersistenceExcep
tion: org.hibernate.PropertyAccessException: IllegalArgumentException occurred c
alling getter of com.pix.bean.Country.phoneCode
11:36:12,311 ERROR [STDERR] at com.pix.persistent.model.AbstractPersistence.
doProcess(AbstractPersistence.java:44)
11:36:12,311 ERROR [STDERR] at com.pix.manager.PersistanceManager.doProcess(
PersistanceManager.java:43)
11:36:12,311 ERROR [STDERR] ... 32 more
11:36:12,311 ERROR [STDERR] Caused by: org.hibernate.PropertyAccessException: Il
legalArgumentException occurred calling getter of com.pix.bean.Country.phoneCode
11:36:12,311 ERROR [STDERR] at org.hibernate.property.BasicPropertyAccessor$
BasicGetter.get(BasicPropertyAccessor.java:171)
11:36:12,311 ERROR [STDERR] at org.hibernate.property.BasicPropertyAccessor$
BasicGetter.getForInsert(BasicPropertyAccessor.java:182)
11:36:12,311 ERROR [STDERR] at org.hibernate.tuple.AbstractEntityTuplizer.ge
tPropertyValuesToInsert(AbstractEntityTuplizer.java:264)
11:36:12,311 ERROR [STDERR] at org.hibernate.tuple.PojoEntityTuplizer.getPro
pertyValuesToInsert(PojoEntityTuplizer.java:209)
11:36:12,311 ERROR [STDERR] at org.hibernate.persister.entity.AbstractEntity
Persister.getPropertyValuesToInsert(AbstractEntityPersister.java:3445)
11:36:12,311 ERROR [STDERR] at org.hibernate.event.def.AbstractSaveEventList
ener.performSaveOrReplicate(AbstractSaveEventListener.java:263)
11:36:12,311 ERROR [STDERR] at org.hibernate.event.def.AbstractSaveEventList
ener.performSave(AbstractSaveEventListener.java:180)
11:36:12,311 ERROR [STDERR] at org.hibernate.event.def.AbstractSaveEventList
ener.saveWithGeneratedId(AbstractSaveEventListener.java:108)
11:36:12,311 ERROR [STDERR] at org.hibernate.event.def.DefaultSaveOrUpdateEv
entListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java
:186)
11:36:12,311 ERROR [STDERR] at org.hibernate.event.def.DefaultSaveEventListe
ner.saveWithGeneratedOrRequestedId(DefaultSaveEventListener.java:33)
11:36:12,311 ERROR [STDERR] at org.hibernate.event.def.DefaultSaveOrUpdateEv
entListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:175)
11:36:12,311 ERROR [STDERR] at org.hibernate.event.def.DefaultSaveEventListe
ner.performSaveOrUpdate(DefaultSaveEventListener.java:27)
11:36:12,311 ERROR [STDERR] at org.hibernate.event.def.DefaultSaveOrUpdateEv
entListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:70)
11:36:12,311 ERROR [STDERR] at org.hibernate.impl.SessionImpl.fireSave(Sessi
onImpl.java:537)
11:36:12,311 ERROR [STDERR] at org.hibernate.impl.SessionImpl.save(SessionIm
pl.java:525)
11:36:12,311 ERROR [STDERR] at org.hibernate.impl.SessionImpl.save(SessionIm
pl.java:521)
11:36:12,311 ERROR [STDERR] at com.pix.persistent.model.AbstractPersistence.
doProcess(AbstractPersistence.java:27)
11:36:12,311 ERROR [STDERR] ... 33 more
11:36:12,311 ERROR [STDERR] Caused by: java.lang.IllegalArgumentException: objec
t is not an instance of declaring class
11:36:12,311 ERROR [STDERR] at sun.reflect.NativeMethodAccessorImpl.invoke0(
Native Method)
11:36:12,311 ERROR [STDERR] at sun.reflect.NativeMethodAccessorImpl.invoke(N
ativeMethodAccessorImpl.java:39)
11:36:12,311 ERROR [STDERR] at sun.reflect.DelegatingMethodAccessorImpl.invo
ke(DelegatingMethodAccessorImpl.java:25)
11:36:12,311 ERROR [STDERR] at java.lang.reflect.Method.invoke(Method.java:5
85)
11:36:12,311 ERROR [STDERR] at org.hibernate.property.BasicPropertyAccessor$
BasicGetter.get(BasicPropertyAccessor.java:145)
11:36:12,311 ERROR [STDERR] ... 49 more
Name and version of the database you are using:
Mysql 5.0.18
|