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: Mapping Question - Look up tables & objects
PostPosted: Wed Dec 20, 2006 12:54 pm 
Newbie

Joined: Wed Dec 20, 2006 12:34 pm
Posts: 13
I have a simple model that contains a certificate and a status. These are represented by two different tables in the database. Also they are represented respectively by two classes in vb.net. The mapping files are as follows.

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
<class name="CertificateManagement.Certificate, CertificateManagement" table="certificate" >
<id name="Id" column="CERTIFICATE_ID" type="int" length="11">
<generator class="assigned" />
</id>
<version name="Version" column="VERSION" type="int" unsaved-value="0"/>

<property name="CertificateNumber" column="CERTIFICATE_NUMBER" type="String" length="30"/>
<property name="TaxYear" column="TAX_YEAR" type="Boolean" length="4"/>
<!--<property name="Certificate_Date" column="CERTIFICATE_DATE" type="DateTime" />-->
<property name="Township" column="TOWNSHIP" type="String" length="40"/>
<property name="ParcelNumber" column="PARCEL_NUMBER" type="String" length="40"/>
<property name="TractNumber" column="TRACT_NUMBER" type="String" length="40"/>
<property name="Frontage" column="FRONTAGE" type="Double" />
<property name="Depth" column="DEPTH" type="Double" />
<many-to-one name="Status" class="CertificateManagement.Status, CertificateManagement" column="STATUS" />

</class>

</hibernate-mapping>


<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
<class name="CertificateManagement.Status, CertificateManagement" table="status" >
<id name="STATUS" column="STATUS" type="String" length="1" >
<generator class="assigned" />
</id>
<property name="Name" column="STATUS_NAME" type="String" length="15"/>
<property name="Description" column="STATUS_DESCRIPTION" type="String" length="50"/>
</class>

</hibernate-mapping>


I can successfully load my certificate which is composed of amoung other things a status object. The problem arrises when i want to change the status of the certificate. How do i do this?

I have tried CertificateObject.StatusObject.Status="C" but this is trying to edit the Status table which cannot be done because the Status column on that table is the primary key. But that is not the problem. I only want to change the status column in the certificate table and have that change proprogated into a new StatusObject.

Any help will be much appreciated


Top
 Profile  
 
 Post subject: Re: Mapping Question - Look up tables & objects
PostPosted: Wed Dec 20, 2006 1:20 pm 
Newbie

Joined: Wed Dec 20, 2006 9:00 am
Posts: 10
Location: Brazil (GMT-3)
wdrone wrote:

I can successfully load my certificate which is composed of amoung other things a status object. The problem arrises when i want to change the status of the certificate. How do i do this?

I have tried CertificateObject.StatusObject.Status="C" but this is trying to edit the Status table which cannot be done because the Status column on that table is the primary key. But that is not the problem. I only want to change the status column in the certificate table and have that change proprogated into a new StatusObject.

Any help will be much appreciated


Correct me if I'm wrong, but I think you meant to write CertificateObject.Status.Status = "C" by what I can read from your mapping.
Any way, as you correctly pointed out, you are trying to change the primary key and that will be impossible. You have to assign a whole Status object to your certificate's status. You can create a new object or you can retrieve a pre-existing one. Creating a new one may leave the old object hanging in your database and I believe that isn't what you want since "status" seems something limited in number by nature. So, try some code like this:

Code:

Dim StatusID as String = "MYID"
Dim St as Status = Session.Load(GetType(Status), StatusID)
CertificateObject.Status = St



I hope that helps...

Luis


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 20, 2006 3:17 pm 
Newbie

Joined: Wed Dec 20, 2006 12:34 pm
Posts: 13
That did it. It works great now.

Thanks luismalheiro


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.