-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 posts ] 
Author Message
 Post subject: One to Many Mapping inserting only the first object
PostPosted: Wed Apr 07, 2010 10:49 am 
Newbie

Joined: Wed Apr 07, 2010 10:44 am
Posts: 2
Hi All,

I am using one to many mapping and trying to store few records. I am using Spring 3 with Hibernate 3.
Mapping
Code:
# <?xml version="1.0"?> 
# <!DOCTYPE hibernate-mapping PUBLIC 
#         "-//Hibernate/Hibernate Mapping DTD 3.0//EN" 
#         "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"> 
#   
# <hibernate-mapping> 
#       
#   <class name="myexample.Research" table="***"> 
#     <id name="researchId" column="RESEARCH_ID"> 
#         <generator class="native"/> 
#     </id> 
#   <property name="a" column="a"></property> 
#   <set name="researchAttach" cascade="all" lazy="false"> 
#     <key column="RESEARCH_ID" not-null="true"/> 
#     <one-to-many class="myexample.ResearchAttachment"/> 
#  </set> 
# </class> 
# <class name="com.aexp.forms.classes.ResearchAttachment" table="***"> 
#     <id name="attachID" column="RESEARCH_ATTACH_ID"> 
#         <generator class="native"/> 
#     </id> 
#   <property name="b" column="b"></property> 
#     
# </class> 
# </hibernate-mapping> 

When I execute this example . Only the first object "test attachment 111" gets inserted in the database.
The second one "test attachment 222" does not get inserted in the database.
Code:
# Set<ResearchAttachment> reslist = new TreeSet<ResearchAttachment>(); 
#             ResearchAttachment att1 = new ResearchAttachment(); 
#             att1.setAttachName("test attachment 111"); 
#             ResearchAttachment att2 = new ResearchAttachment(); 
#             att2.setAttachName("test attachment222"); 
#             reslist.add(att1); 
#             reslist.add(att2); 
#               
#             int i = 101; 
#             System.out.println("here1"); 
#             Research r = new Research(); 
#             Research reas = (Research) dao.getFormByIDService(r,i); 
#             System.out.println("count="+reas.getClient()); 
#             System.out.println("here5"); 
#             reas.setClient("yey ad got ha ha ha i did it"); 
#             reas.setAdvertiser("epicurean"); 
#         reas.setResearchAttach(reslist); 
# dao.saveOrUpdateService(reas); 

Code:
#  public void saveOrUpdateService(T objectType) { 
#         formsDao.saveOrUpdateObject(objectType); 
#     } 

Code:
# public void saveOrUpdateObject(T objectType) throws DataAccessException { 
#         this.hibernateTemplate.saveOrUpdate(objectType); 
# } 

Thanks


Top
 Profile  
 
 Post subject: Re: One to Many Mapping inserting only the first object
PostPosted: Thu Apr 08, 2010 10:08 am 
Newbie

Joined: Wed Apr 07, 2010 10:44 am
Posts: 2
Any suggestion please
Thanks


Top
 Profile  
 
 Post subject: Re: One to Many Mapping inserting only the first object
PostPosted: Thu Apr 08, 2010 1:45 pm 
Newbie

Joined: Thu Jul 26, 2007 8:25 am
Posts: 6
the issue is with native generator class, it can't generate two keys. replace it with assigned, it will work.


Top
 Profile  
 
 Post subject: Re: One to Many Mapping inserting only the first object
PostPosted: Fri Apr 10, 2015 12:56 am 
Newbie

Joined: Fri Apr 10, 2015 12:54 am
Posts: 2
Hello,
I'm having the same problem with JPA, can anyone help with that, thanks


Top
 Profile  
 
 Post subject: Re: One to Many Mapping inserting only the first object
PostPosted: Fri Apr 10, 2015 12:57 am 
Newbie

Joined: Fri Apr 10, 2015 12:54 am
Posts: 2
Hello,
I'm having the same problem with JPA, can anyone help with that, thanks


Top
 Profile  
 
 Post subject: Re: One to Many Mapping inserting only the first object
PostPosted: Wed Apr 15, 2015 8:48 pm 
Newbie

Joined: Wed Apr 15, 2015 8:32 pm
Posts: 1
Location: India
Generator class creating problem for you..I have one question ehy are still using xml mapping instead of annotation..

Devloper- http://www.careergoal.in


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.