-->
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: Mapping a parent-child relationship on a single table
PostPosted: Fri Feb 15, 2008 5:46 am 
Newbie

Joined: Fri Feb 15, 2008 4:46 am
Posts: 5
Location: UK
Is it possible to map a parent-child relationship on the same table in Hibernate?

For example,

<class name="tlss.TLSSProcess" table="TLSS_PROCESSES">
<id name="id" column="ID">
<generator class="native"/>
</id>

<many-to-one name="parent"
class="tlss.TLSSProcess"
column="tlss_process_id"/>

<set name="children" inverse="true" >
<key column="ID"/>
<one-to-many class="tlss.TLSSProcess"/>
</set>

In trying to save instances of this class, I was getting transient object issues. Where would it be best to put the cascade="all"? Tried putting it on the children and I got concurrency issues.

_________________
Ann


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 15, 2008 6:28 am 
Regular
Regular

Joined: Wed Jun 20, 2007 1:53 am
Posts: 75
Your set asscoiation is wrong. It should be,

<set name="children" inverse="true" >
<key column="tlss_process_id"/>
<one-to-many class="tlss.TLSSProcess"/>
</set>


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 15, 2008 12:11 pm 
Newbie

Joined: Fri Feb 15, 2008 4:46 am
Posts: 5
Location: UK
Thank you for your reply.

I did notice that error and have changed it. However, I'm still getting a concurrent modification exception. Any suggestions?

Regards,
Ann

_________________
Ann


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 18, 2008 2:30 am 
Regular
Regular

Joined: Wed Jun 20, 2007 1:53 am
Posts: 75
Post your code between session.open and session.close()


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 18, 2008 5:41 am 
Newbie

Joined: Fri Feb 15, 2008 4:46 am
Posts: 5
Location: UK
The problem is that we are trying to pass an instance associated with Hibernate to a rules engine (jrules). This will fire rules and add things to the instance that we cannot predict. Perhaps we cannot do it this way but it would be nice if we could!

Thanks, Ann


Code:

TlssrulesResult tlssrulesresult = null;
      session = HibernateUtil.getSessionFactory().getCurrentSession();
      session.beginTransaction();
      
   
      ContractDao contractDao = new  ContractDao();
      contract = contractDao.getContract("aston", session);
      
      ContractConstraint cc = new ContractConstraint("cc1", "SOM level", contract, tlss.SOM.CapabilityServiceOnBalanceSheet);
      Parameter opConst1 = new Parameter("opConst1","operational_autonomy","yes");
      ContractConstraint cc2 = new ContractConstraint("cc2", "support constraint",contract,opConst1);

      Parameter opConst2 = new Parameter("opConst2","mission_profile","yes");
      ContractConstraint cc3 = new ContractConstraint("cc3", "support constraint",contract,opConst2);

      Parameter opConst3 = new Parameter("opConst3","accessibility_in_theatre","yes");
      ContractConstraint cc4 = new ContractConstraint("cc4", "support constraint",contract,opConst3);

      
      IlrRuleSessionProvider rsProvider = new IlrRuleSessionProviderFactory.Builder(
            IlrRuleSessionProviderFactory.SIMPLE_RULESESSION_PROVIDER).build();

      IlrStatelessRuleSession rs = rsProvider   .createStatelessRuleSession();

      IlrSessionRequest request1 = new IlrSessionRequest(rulesetPath);
      
      IlrSessionExecutionSettings execSettings = request1.getExecutionSettings();
      IlrSessionParameters params = execSettings.getInputParameters();
      params.setParameter("contract", contract);

      // Executes the ruleset
      IlrSessionResponse response1 = rs.executeRules(request1);
   
      tlssrulesresult = new TlssrulesResult();       
      
      tlssrulesresult.contract = (Contract) response1.getExecutionResult().getOutputParameters().getObjectValue(
      "contract");
      
      
      tlssrulesresult.userdata = (String)response1.getExecutionProperties().getUserData();
      tlssrulesresult.outputString = response1.getExecutionResult().getOutputString();

      
      session.saveOrUpdate(contract);
      session.getTransaction().commit();


_________________
Ann


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.