-->
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.  [ 5 posts ] 
Author Message
 Post subject: parent/child Category Like Objects - wont update link table
PostPosted: Tue Jul 10, 2007 1:27 am 
Newbie

Joined: Thu Mar 29, 2007 10:26 am
Posts: 9
I have tried this a number of ways and most recently tried the mapping this way. The paradigm is so common that i know this has to be handled from the framework - but i am missing something from all the books i have bought, information browsed online, etc...
I have a DomainBean which might contain optional one or more child domains and one or more optional parent domains. I am using a link table to connect the associated rows but the link table is not getting updated when i set the associations in the objects (using Sets) - only the domain table is being inserted into. I tried using a join tag at one point and that didnt work. guess i am missing something fundamental here. Any help would be appreciated.

Hibernate version: 3.2.4

Mapping documents:

<!-- ====================== DOMAIN BEAN ================================== -->
<class name="core.business.domain.DomainBean" table="domain_tbl">
<id name="domainID" column="domain_id" type="integer">
<generator class="native"></generator>
</id>

<set name="subDomains" table="domain_mapping_tbl">
<key column="parent_domain_id"/>
<many-to-many class="core.business.domain.DomainBean" column="child_domain_id" />
</set>

<set name="parentDomains" table="domain_mapping_tbl">
<key column="child_domain_id"/>
<many-to-many class="core.business.domain.DomainBean" column="parent_domain_id" />
</set>

<property type="integer"
column="domain_type_id"
name="domainType"
access="property" />
<property type="integer"
column="domain_owner_id"
name="domainOwnerID"
access="property" />
<property type="string"
column="domain_name"
name="domainName"
access="property" />
<property type="string"
column="domain_desc"
name="domainDescription"
access="property" />

</class>




Code between sessionFactory.openSession() and session.close():


Session session = ApplicationStartupListener.getFactory(this.getServlet().getServletContext()).openSession();
HashMap domainLinksMap = new HashMap();
DomainManager manager = new DomainManager();

if(!errors.isEmpty()){
this.saveErrors(request,errors);
return mapping.getInputForward();
}

if( request.getParameter("domainID") != null && request.getParameter("domainName") == null ){

if(request.getParameter("domainID") != null){
int topDOmainID = Integer.parseInt(request.getParameter("domainID"));
DomainBean topDomain = manager.getDomain(session, topDOmainID);
request.setAttribute("parentDomain", topDomain);
}

} else {

try{
int topDOmainID = Integer.parseInt(request.getParameter("domainID"));
DomainBean topDomain = manager.getDomain(session, topDOmainID);
Map map = this.mapParams(request);
bean = manager.createSubDomain(session, map);
topDomain.getSubDomains().add(bean);
bean.getParentDomains().add(topDomain);
session.update( topDomain );
session.update( bean );
//Query setJoinedCriteria = session.createQuery("Insert Into domain_mapping_tbl values(?,?,?)");
//setJoinedCriteria.setInteger(1, topDomain.getDomainID());
//setJoinedCriteria.setInteger(2, bean.getDomainID());
//setJoinedCriteria.setInteger(3, 0);
// int update = setJoinedCriteria.executeUpdate();
request.setAttribute("domain", bean);
domainLinksMap.put("domainID",bean.getDomainID());
}
catch(Exception e)
{

e.printStackTrace(System.out);
return mapping.getInputForward();

} finally{

session.disconnect();
session.close();

}


Full stack trace of any exception that occurs: No exceptions

Name and version of the database you are using: MySQL 5.1

The generated SQL (show_sql=true):
01:23:06,828 INFO [STDOUT] Hibernate: insert into core.domain_tbl (domain_type_id, domain_owner_id, domain_name, domain_desc) values (?, ?, ?, ?)
01:23:06,906 INFO [STDOUT] Hibernate: select subdomains0_.parent_domain_id as parent1_1_, subdomains0_.child_domain_id as child2_1_, domainbean1_.domain_id as domain1_8_0_, domainbean1_.domain_type_id as domain2_8_0_, domainbean1_.domain_owner_id as domain3_8_0_, domainbean1_.domain_name as domain4_8_0_, domainbean1_.domain_desc as domain5_8_0_ from core.domain_mapping_tbl subdomains0_ left outer join core.domain_tbl domainbean1_ on subdomains0_.child_domain_id=domainbean1_.domain_id where subdomains0_.parent_domain_id=?


Debug level Hibernate log excerpt: N/A


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 10, 2007 4:29 am 
Newbie

Joined: Tue Sep 19, 2006 6:47 am
Posts: 15
Looks like you didn't define any cascading for your children. See here: http://www.hibernate.org/hib_docs/refer ... child.html

<set name="children" inverse="true" cascade="all">
<key column="parent_id"/>
<one-to-many class="Child"/>
</set>


Top
 Profile  
 
 Post subject: still doesnt work
PostPosted: Tue Jul 10, 2007 11:49 am 
Newbie

Joined: Thu Mar 29, 2007 10:26 am
Posts: 9
didnt work with the changes i put in - see below:

Code:
     <set name="subDomains" table="domain_mapping_tbl"[b] inverse="true" cascade="all"[/b]>
        <key column="parent_domain_id"/>
        <many-to-many class="core.business.domain.DomainBean" column="child_domain_id" />
     </set>
       
     <set name="parentDomains" table="domain_mapping_tbl">
        <key column="child_domain_id"/>
        <many-to-many class="core.business.domain.DomainBean" column="parent_domain_id" />
     </set>


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 11, 2007 9:22 pm 
Beginner
Beginner

Joined: Tue Jun 26, 2007 2:31 pm
Posts: 21
try changing this remove inverse="true" in the code... let me know if this works


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 12, 2007 4:35 am 
Newbie

Joined: Thu Mar 29, 2007 10:26 am
Posts: 9
nope - thats how i had it before i added it. thanks.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 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.