aspose file tools*
The moose likes Object Relational Mapping and the fly likes hibernate 1-many error Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "hibernate 1-many error" Watch "hibernate 1-many error" New topic
Author

hibernate 1-many error

raj baig
Ranch Hand

Joined: Jul 11, 2006
Posts: 96
hai,

i have a base class and a child class. in base class i declared a variable of type set which is child class. i am trying to store the data of base table using session.save(base). will it store the data of child also? as i used Set. i have written in mapping file 1-m relationship.
it is giving me the error.

base class properties : String accid,String accname,privaet Set user
child class properties : String userid,accid,uname,pwd

my.package.Account acc=new my.package.Account();

Set hs=new HashSet();
hs.add("1");
hs.add("1");
hs.add("warner");
hs.add("warner");

acc.setAccname("p&g");
acc.setUser(hs);

session.save(acc);



Error:

Exception in thread "main" org.hibernate.PropertyAccessException: IllegalArgumen
tException occurred calling getter of sas.login.User.userid
at org.hibernate.property.BasicPropertyAccessor$BasicGetter.geti want to store the base and child table data.
at org.hibernate.property.BasicPropertyAccessor$BasicGetter.get(BasicPr
ertyAccessor.java:171)
at org.hibernate.tuple.AbstractEntityTuplizer.getIdentifier(AbstractEnt
yTuplizer.java:176)
at org.hibernate.persister.entity.AbstractEntityPersister.getIdentifier
bstractEntityPersister.java:3257)
at org.hibernate.persister.entity.AbstractEntityPersister.isTransient(A
tractEntityPersister.java:2983)
at org.hibernate.engine.ForeignKeys.isTransient(ForeignKeys.java:181)
at org.hibernate.event.def.AbstractSaveEventListener.getEntityState(Abs
actSaveEventListener.java:460)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.performSave
Update(DefaultSaveOrUpdateEventListener.java:84)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpd
e(DefaultSaveOrUpdateEventListener.java:70)
at org.hibernate.impl.SessionImpl.fireSaveOrUpdate(SessionImpl.java:502

at org.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java:494)
at org.hibernate.engine.CascadingAction$1.cascade(CascadingAction.java:
4)
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:
0)
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.event.def.AbstractSaveEventListener.cascadeAfterSave(A
tractSaveEventListener.java:410)
at org.hibernate.event.def.AbstractSaveEventListener.performSaveOrRepli
te(AbstractSaveEventListener.java:299)
at org.hibernate.event.def.AbstractSaveEventListener.performSave(Abstra
SaveEventListener.java:167)
at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedI
AbstractSaveEventListener.java:114)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.saveWithGen
atedOrRequestedId(DefaultSaveOrUpdateEventListener.java:186)
at org.hibernate.event.def.DefaultSaveEventListener.saveWithGeneratedOr
questedId(DefaultSaveEventListener.java:33)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsTra
ient(DefaultSaveOrUpdateEventListener.java:175)
at org.hibernate.event.def.DefaultSaveEventListener.performSaveOrUpdate
efaultSaveEventListener.java:27)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpd
e(DefaultSaveOrUpdateEventListener.java:70)
at org.hibernate.impl.SessionImpl.fireSave(SessionImpl.java:530)
at org.hibernate.impl.SessionImpl.save(SessionImpl.java:518)
at org.hibernate.impl.SessionImpl.save(SessionImpl.java:514)
at Test.main(Test.java:23)
aused by: java.lang.IllegalArgumentException: object is not an instance of dec
ring class
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl
ava:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcce
orImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.hibernate.property.BasicPropertyAccessor$BasicGetter.get(BasicPr
ertyAccessor.java:145)

thank you ......help required
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17250
    
    6

Your POJO needs to have both getters and setters for the properties. I think one of them is missing. Please post you Java code and the mapping files for the POJO. Also in your mapping from the one side you need to set your cascade option to save-update. I'd also make sure that the inverse="true" is on the many side mapping.

Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: hibernate 1-many error