-->
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.  [ 3 posts ] 
Author Message
 Post subject: Foreign key not saved.
PostPosted: Fri Feb 17, 2006 1:06 pm 
Beginner
Beginner

Joined: Fri Nov 11, 2005 1:04 pm
Posts: 22
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version: 1.0.2

Mapping documents:
For Account
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
   <class name="DirectBill.Common.Domain.Account,DirectBill.Common" table="tblAccount">
      <id name="AcctId" column="ACCT_ID" type="Int32" unsaved-value="0">
         <generator class="native"/>
      </id>
      <version column="CHANGEID" type="Int32" name="Changeid" unsaved-value="0" />
      <bag name="AccountHistoryList" inverse="false" lazy="false" >
         <key column="ACCTID" />
         <one-to-many class="DirectBill.Common.Domain.AccountHistory,DirectBill.Common" />
      </bag>
      <bag name="AcctStatusList" inverse="false" lazy="false" table="tblAcctStatus">
         <key column="ACCTID" />
         <many-to-many class="DirectBill.Common.Domain.AcctStatusType,DirectBill.Common" column="ACCTSTATUSID" />
      </bag>
      <bag name="ANIAccessList" inverse="true" lazy="true" >
         <key column="ACCT" />
         <one-to-many class="DirectBill.Common.Domain.ANIAccess,DirectBill.Common" />
      </bag>
      <bag name="BillingInformationList" inverse="true" lazy="false" >
         <key column="ACCT" />
         <one-to-many class="DirectBill.Common.Domain.BillingInformation,DirectBill.Common" />
      </bag>
      <bag name="BlockHistoryList" inverse="true" lazy="true" >
         <key column="ACCT" />
         <one-to-many class="DirectBill.Common.Domain.BlockHistory,DirectBill.Common" />
      </bag>
      <bag name="TransactionList" inverse="true" lazy="false" >
         <key column="ACCT" />
         <one-to-many class="DirectBill.Common.Domain.Transaction,DirectBill.Common" />
      </bag>
      <property column="ANI" type="String" name="ANI" length="10" />
      <many-to-one name="Currentbilling" column="CURRENTBILLING" class="DirectBill.Common.Domain.BillingInformation,DirectBill.Common" />
      <property column="LASTCONTACT" type="DateTime"  access="field"  name="m_lastcontact"/>
      <property column="NOTES" type="String" name="Notes" length="256" />
      <property column="PASSWORD" type="String" name="Password" length="50" />
      
      
   </class>
</hibernate-mapping>


For transaction

Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
   <class name="DirectBill.Common.Domain.Transaction,DirectBill.Common" table="tblTransaction">
      <id name="TransactionID" column="TRANSACTIONID" type="Int32" unsaved-value="0">
         <generator class="native"/>
      </id>
      <many-to-one name="Acct" column="ACCT" insert="true" class="DirectBill.Common.Domain.Account,DirectBill.Common" />
      <many-to-one name="Transactiontypeid" column="TRANSACTIONTYPEID" class="DirectBill.Common.Domain.TransactionType,DirectBill.Common" />
      <many-to-one name="Enteredby" column="ENTEREDBY" class="DirectBill.Common.Domain.User,DirectBill.Common" />
      <property column="TRANSACTIONDATE" type="DateTime" access="field" name="m_TransactionDate" />
      <property column="ISCREDIT" type="Boolean" name="Iscredit" />
      <property column="AMOUNT" type="Decimal" name="Amount" />
      <property column="TRANSACTIONCLEARED" type="Boolean" name="Transactioncleared" />      
   </class>
</hibernate-mapping>


Code between sessionFactory.openSession() and session.close():
This may the problem, my code spans two sessions. First I use a session to retrieve an account. I then set the ACCT property of my Transaction to that account I retrieve. Finally I save the Transaction. When I look at the database, everything is properly persisted except for the reference to the account (the acct column). When looking at the generated SQL, I can see the ACCT parameter being made but the value passed in is '' . Do I need to change my code to handle all of this in one session or is there a bug here?

Full stack trace of any exception that occurs: No Exception

Name and version of the database you are using: MSSQL 2005 Standard

Can someone provide some advice on how to make this work properly?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 17, 2006 7:58 pm 
Senior
Senior

Joined: Wed Jun 15, 2005 4:17 am
Posts: 156
post the code.

cheers,
radu


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 17, 2006 8:42 pm 
Beginner
Beginner

Joined: Fri Nov 11, 2005 1:04 pm
Posts: 22
Don't worry I figured it out.


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