• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Junilu Lacar
  • Martin Vashko
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Scott Selikoff
  • salvin francis
  • Piet Souris

problem with hibernate

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 518
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
I've never won anything before. Not even a tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!