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