File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Object Relational Mapping and the fly likes problem with hibernate Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "problem with hibernate" Watch "problem with hibernate" New topic
Author

problem with hibernate

praveen potty
Greenhorn

Joined: Jun 08, 2006
Posts: 4
Hi
I am facing a problem with the Hibernate framework.
I have a parent table and associate child table
When I try to insert a record to the Parent it is not inserting the record to the child.It is getting inserted to the parent.
I am not getting any exception also
I am using sesson.save(parent object).

do I need to explicitly do session.save(child object)?
mapping xml for the parent

<hibernate-mapping package="com.ert.nwcs.symbology.dataaccess">
<class name="TbNewsCode" table="TB_NEWS_CODE" schema="NWCS">
<id name="newsCodeId" type="big_decimal">
<column name="NEWS_CODE_ID" precision="22" scale="0" />
<generator class="assigned" />
</id>
<property name="newsCode" type="string">
<column name="NEWS_CODE" length="10" not-null="true" />
</property>
<property name="newsType" type="big_decimal">
<column name="NEWS_TYPE" precision="22" scale="0" not-null="true" />
</property>
<set name="tbNewsCodeChild" inverse="true" >
<key>
<column name="NEWS_CODE_ID" precision="22" scale="0" not-null="true" />
</key>
<one-to-many class="TbNewsCodeChild" />
</set>
</class>
</hibernate-mapping>

mapping xml for child

<hibernate-mapping package="com.ert.nwcs.symbology.dataaccess">
<class name="TbNewsCodeParent" table="TB_NEWS_CODE_CHILD" schema="NWCS">
<composite-id name="id" class="TbNewsCodeChildId">
<key-many-to-one name="tbNewsCode" class="TbNewsCode">
<column name="NEWS_CODE_ID" precision="22" scale="0" />
</key-many-to-one>
<key-property name="childCode" type="string">
<column name="CHILD_CODE" />
</key-property>
</composite-id>
</class>
</hibernate-mapping>

Please help me resolve this problem.
I tried using cascade="all" or cascade ="save-update" option in the parent mapping xml, but it is giving me some error when it tries to access the getter method of child
Scott Johnson
Ranch Hand

Joined: Aug 24, 2005
Posts: 518
You don't need to do an explicit session.save(child) if you set cascade to "all" or "save-update" so you're on the right track.

I tried using cascade="all" or cascade ="save-update" option in the parent mapping xml, but it is giving me some error when it tries to access the getter method of child


Please post the details of the exception that was thrown.
praveen potty
Greenhorn

Joined: Jun 08, 2006
Posts: 4
Hi,
The exception is thrown when it tries to access the getter method of child class

As you may be aware there are two child class
1. BaseTbNewsCodeChild
2.BaseTbNewsCodeChildId

if you see the below exception it says that error occured calling the getter method of child class.id. I am not able to understand this.
When I debugged the program the Parent object,at the time of
session.save(), has the child class attributes in the set(The parent object has a set(hashset)attribute which has the value of the child as a string object).
I assume that the Hibernate will set the id and other properties of the child when we save the parent. but it it is not happening for me.


org.hibernate.PropertyAccessException: IllegalArgumentException occurred calling getter of com.ert.nwcs.symbology.dataaccess.base.BaseTbNewsCodeChild.id
at org.hibernate.property.BasicPropertyAccessor$BasicGetter.get(BasicPropertyAccessor.java:171)
at org.hibernate.tuple.AbstractEntityTuplizer.getIdentifier(AbstractEntityTuplizer.java:176)
at org.hibernate.persister.entity.AbstractEntityPersister.getIdentifier(AbstractEntityPersister.java:3257)
at org.hibernate.persister.entity.AbstractEntityPersister.isTransient(AbstractEntityPersister.java:2983)
at org.hibernate.engine.ForeignKeys.isTransient(ForeignKeys.java:181)
at org.hibernate.event.def.AbstractSaveEventListener.getEntityState(AbstractSaveEventListener.java:460)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.performSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:84)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:70)
at org.hibernate.impl.SessionImpl.fireSaveOrUpdate(SessionImpl.java:520)
at org.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java:513)
at org.hibernate.engine.CascadingAction$1.cascade(CascadingAction.java:134)
at org.hibernate.engine.Cascade.cascadeToOne(Cascade.java:213)
at org.hibernate.engine.Cascade.cascadeAssociation(Cascade.java:157)
at org.hibernate.engine.Cascade.cascadeProperty(Cascade.java:108)
at org.hibernate.engine.Cascade.cascadeCollectionElements(Cascade.java:290)
at org.hibernate.engine.Cascade.cascadeCollection(Cascade.java:185)
at org.hibernate.engine.Cascade.cascadeAssociation(Cascade.java:160)
at org.hibernate.engine.Cascade.cascadeProperty(Cascade.java:108)
at org.hibernate.engine.Cascade.cascade(Cascade.java:248)
at org.hibernate.engine.Cascade.cascade(Cascade.java:223)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.cascadeOnUpdate(DefaultSaveOrUpdateEventListener.java:331)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.performUpdate(DefaultSaveOrUpdateEventListener.java:303)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsDetached(DefaultSaveOrUpdateEventListener.java:216)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.performSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:93)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:70)
at org.hibernate.impl.SessionImpl.fireSaveOrUpdate(SessionImpl.java:520)
at org.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java:513)
at org.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java:509)
at com.dowjones.nwcs.symbology.dataaccess.dao.TbNewsCodeDAOImpl.insertRecords(TbNewsCodeDAOImpl.java:31)
at com.dowjones.nwcs.symbology.service.SymbologyServiceImpl.SynchronizeTables(SymbologyServiceImpl.java:74)
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.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:287)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:165)
at $Proxy2.SynchronizeTables(Unknown Source)
at com.dowjones.nwcs.symbology.service.CodeServiceImpl.SynchronizeTables(CodeServiceImpl.java:49)
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.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:287)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:165)
at $Proxy0.SynchronizeTables(Unknown Source)
at com.dowjones.nwcs.symbology.scheduler.FileProcessor.updateTables(FileProcessor.java:1052)
at com.dowjones.nwcs.symbology.scheduler.FileProcessor.processWeeklyNewsCodeFiles(FileProcessor.java:388)
at com.dowjones.nwcs.symbology.scheduler.FileProcessor.processWeeklyContentDO(FileProcessor.java:189)
at com.dowjones.nwcs.symbology.scheduler.FileProcessor.processWeeklyFiles(FileProcessor.java:178)
at com.dowjones.nwcs.symbology.scheduler.FileProcessor.processFiles(FileProcessor.java:54)
at com.dowjones.nwcs.symbology.scheduler.WeeklyFileDownloader.getfile(WeeklyFileDownloader.java:37)
at com.dowjones.nwcs.symbology.scheduler.WeeklyFileDownloader.main(WeeklyFileDownloader.java:27)
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)
... 51 more
praveen potty
Greenhorn

Joined: Jun 08, 2006
Posts: 4
Hi ,

I am sorry to give you one more information
I am using the HIbernateDAO support for my DAO classes.
ie my DAO class extends HibenateDAOSupport

thanks
Praveen
praveen potty
Greenhorn

Joined: Jun 08, 2006
Posts: 4
Hi All,
I was able to solve the problem
my parent object set contained the string attibutes which actually should have contained the child objects.

sorry for my folly

Thanks
praveen
Priyadarshini Rajendran
Greenhorn

Joined: Oct 14, 2008
Posts: 1
Hullo,
can someone help me out to solve this?

org.hibernate.PropertyAccessException: IllegalArgumentException occurred while calling setter of com.impiger.sdp.vas.data.user.User.roleID
at org.hibernate.property.BasicPropertyAccessor$BasicSetter.set(BasicPropertyAccessor.java:104)
at org.hibernate.tuple.entity.AbstractEntityTuplizer.setPropertyValues(AbstractEntityTuplizer.java:337)
at org.hibernate.tuple.entity.PojoEntityTuplizer.setPropertyValues(PojoEntityTuplizer.java:200)
at org.hibernate.persister.entity.AbstractEntityPersister.setPropertyValues(AbstractEntityPersister.java:3566)
at org.hibernate.engine.TwoPhaseLoad.initializeEntity(TwoPhaseLoad.java:129)
at org.hibernate.loader.Loader.initializeEntitiesAndCollections(Loader.java:854)
at org.hibernate.loader.Loader.doQuery(Loader.java:729)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:236)
at org.hibernate.loader.Loader.doList(Loader.java:2220)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2104)
at org.hibernate.loader.Loader.list(Loader.java:2099)
at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:378)
at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:338)
at org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:172)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1121)
at org.hibernate.impl.QueryImpl.list(QueryImpl.java:79)
at com.impiger.sdp.vas.services.user.impl.UserServicesImpl.getUserDetails(UserServicesImpl.java:37)
at com.impiger.sdp.vas.web.user.actions.Login.execute(Login.java:45)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.opensymphony.xwork2.DefaultActionInvocation.invokeAction(DefaultActionInvocation.java:404)
at com.opensymphony.xwork2.DefaultActionInvocation.invokeActionOnly(DefaultActionInvocation.java:267)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:229)
at com.impiger.web.interceptors.SessionInViewInterceptor.intercept(SessionInViewInterceptor.java:66)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)
at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)
at org.apache.struts2.interceptor.ServletConfigInterceptor.intercept(ServletConfigInterceptor.java:170)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)
at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)
at org.apache.struts2.impl.StrutsActionProxy.execute(StrutsActionProxy.java:50)
at org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:504)
at org.apache.struts2.dispatcher.FilterDispatcher.doFilter(FilterDispatcher.java:419)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:263)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:584)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
at java.lang.Thread.run(Thread.java:619)
Caused by: java.lang.IllegalArgumentException: argument type mismatch
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.hibernate.property.BasicPropertyAccessor$BasicSetter.set(BasicPropertyAccessor.java:42)
... 49 more


Thanks
 
 
subject: problem with hibernate
 
Similar Threads
Common DAO layer Code Base - Hibernate Mapping XML changes
Classcast exception
Child object is not saving.
Hibernate Issue
Persisting one-to-many object using sql-insert