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 Error with <many-to-one> mapping Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Error with <many-to-one> mapping" Watch "Error with <many-to-one> mapping" New topic
Author

Error with <many-to-one> mapping

Nav een
Greenhorn

Joined: May 21, 2011
Posts: 7
Hi,

I am getting the following error while trying to insert a record.

SEVERE: IllegalArgumentException in class: org.nav.tracker.hdto.TemplateDTO, getter method of property: tempID
org.hibernate.PropertyAccessException: IllegalArgumentException occurred calling getter of org.nav.tracker.hdto.TemplateDTO.tempID
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:121)
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 test.Test.main(Test.java:66)
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(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.hibernate.property.BasicPropertyAccessor$BasicGetter.get(BasicPropertyAccessor.java:145)
... 19 more


MApping File :



Code executed :

Rishi Shehrawat
Ranch Hand

Joined: Aug 11, 2010
Posts: 218

In the mapping you have

<many-to-one name="tempID" column="TEMP_ID" class="org.nav.tracker.hdto.TemplateDTO"/>

But in java code you are setting this as String, this I think is causing the problem.
Nav een
Greenhorn

Joined: May 21, 2011
Posts: 7
Rishi Shehrawat wrote:In the mapping you have

<many-to-one name="tempID" column="TEMP_ID" class="org.nav.tracker.hdto.TemplateDTO"/>

But in java code you are setting this as String, this I think is causing the problem.


Here, class is the pojo(model) class in which the foreign key is declared.
prathamesh bandivadekar
Ranch Hand

Joined: May 22, 2008
Posts: 43
can you post your pojo class?


Prathamesh M.B.<br />Java....only.....
Waswani Naresh
Ranch Hand

Joined: May 01, 2008
Posts: 66
Hi Naveen,

As Rishi mentioned, you should have TemplateDTO and not String tempID as a member of TemplateUIDTO class. Though you are trying to make that as foreign key, the way you are doing it is wrong.

Replace

with


While saving TemplateUIDTO object, hibernate will take care of the foreign key (using the hbm file mapping). You need not worry on that front.

Regards,
Naresh Waswani


Naresh Waswani
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Error with <many-to-one> mapping
 
Similar Threads
Error with Hibernate
org.hibernate.PropertyAccessException
many to one unidirectional propertyaccessexception
What is "object is not an instance of declaring class" error in hibernate?
Getting "object is not an instance of declaring class" exception. Please help.