-->
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.  [ 12 posts ] 
Author Message
 Post subject: Exception raised while Using 'set' tag!!!!
PostPosted: Tue Feb 07, 2006 10:05 am 
Newbie

Joined: Tue Feb 07, 2006 9:41 am
Posts: 6
Hi,

I'm using a one-to-many relation between two tables in my application.

table 1 - Id numeric not null (primary key),
BName varchar(20),
IssuedTo numeric

table 2 - UId numeric not null(primary key),
UName varchar(25)

In my table1.hbm.xml -

<many-to-one name="Table2" class="MyAssembly.Table2, MyAssembly" column="UId"/>

and in table1.cs -

private Users user; //also having public property for this

In my table2.hbm.xml -

<set name="Table1">
<key column="IssuedTo"/>
<one-to-many class="MyAssembly.Table1, MyAssembly"/>
</set>

In my table2.cs -

private IDictionary tbl1; //also having public property for this

Now i'm able to save entries to table2 but while saving entry to Table1 i received the following exception

"Invalid mapping information specified for type Core.Users, check your mapping file for property type mismatches"

Inner exception - "Unable to cast object of type 'NHibernate.Collection.Set' to type 'System.Collections.IDictionary'."

Can anyone help me to correct my mistake in this?

Thanks and Regards,
Padmavathy T.


Top
 Profile  
 
 Post subject: Re: Exception raised while Using 'set' tag!!!!
PostPosted: Tue Feb 07, 2006 10:14 am 
Expert
Expert

Joined: Thu Jan 19, 2006 4:29 pm
Posts: 348
Padmavathy wrote:
private IDictionary tbl1; //also having public property for this


Use Iesi.Collections.ISet instead of IDictionary.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 07, 2006 10:55 am 
Newbie

Joined: Tue Feb 07, 2006 9:41 am
Posts: 6
Hi,

Thanks for your reply.

After changing this as you have said, i received another exception at

Table1 tbl1 = (Table1)session.CreateCriteria(typeof(Table1)).Add(NHibernate.Expression.Expression.Eq("Id", id)).SetFetchMode("tbl1", FetchMode.Lazy).List()[0];

saying

"Unable to perform find"

InnerException - "ERROR: 42703: column this.uid does not exist"

Thanks and Regards,
Padmavathy T.


Top
 Profile  
 
 Post subject: Re: Exception raised while Using 'set' tag!!!!
PostPosted: Tue Feb 07, 2006 2:37 pm 
Expert
Expert

Joined: Thu Jan 19, 2006 4:29 pm
Posts: 348
Padmavathy wrote:
table 1 - Id numeric not null (primary key),
BName varchar(20),
IssuedTo numeric

<many-to-one name="Table2" class="MyAssembly.Table2, MyAssembly" column="UId"/>


Here, column="IssuedTo" instead of column="UId", me thinks.

Gert


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 08, 2006 1:33 am 
Newbie

Joined: Tue Feb 07, 2006 9:41 am
Posts: 6
Hi,

Thanks you For your reply.

When i tried by changing column="uid" to column="IssuedTo" ,

<many-to-one name="Table2" class="MyAssembly.Table2, MyAssembly" column="IssuedTo"/>

i got

{"Repated column in mapping for class Core.Table1 should be mapped with insert=\"false\" update=\"false\": IssuedTo"} exception

So i tried in the following ways,

1.I commented the

'property name="IssuedTo" column="IssuedTo" type="int" '

which i gave earlier.

Now it worked well. I'm able to display the entries in the table but fails to insert the values into 'IssuedTo' column.

2. When i completely commented the "<many-to-one../>" mapping and left the <property.../> as it was before, this worked quite well but didnt fetch values for

Users user;//also public property exists

in table1.cs.

What have i done wrong again?

Thanks and Regards,
Padmavathy T.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 08, 2006 2:42 am 
Expert
Expert

Joined: Thu Jan 19, 2006 4:29 pm
Posts: 348
Having a full mapping for both classes might be helpful... From what I have seen:
<many-to-one name="Table2" class="MyAssembly.Table2, MyAssembly" column="IssuedTo"/>

Telss that Table1 class must have property named Table2, with type MyAssembly.Table2

Also, I would write <set name="Table1" inverse="true"> in mapping for Table2

Gert


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 08, 2006 5:30 am 
Newbie

Joined: Tue Feb 07, 2006 9:41 am
Posts: 6
Hi,

My table1.hbm.xml contains,

<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
<class name="MyAssembly.Table1, MyAssembly" table="Table1">
<id name="Id" column="Id" type="int">
<generator class="assigned"/>
</id>
<property name="BName" column="BName" type="string" length="20"/>
<property name="IssuedTo" column="IssuedTo" type="int"/>
<!--<many-to-one name="Table2" class="MyAssembly.Table2, MyAssembly" column="IssuedTo"/>-->
<set name="Table2" inverse="true">
<key column="IssuedTo"/>
<element type="int"/>
</set>
</class>
</hibernate-mapping>


and my table2.hbm.xml has

<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
<class name="MyAssembly.Table2, MyAssembly" table="Table2">
<id name="UId" column="UId" type="int">
<generator class="assigned"/>
</id>
<property name="UName" column="UName" type="string" length="25"/>
<set name="Table1" cascade="none">
<key column="IssuedTo"/>
<one-to-many class="MyAssembly.Table1, MyAssembly"/>
</set>
</class>
</hibernate-mapping>



And in my cs file, i'm having

Table1 table1 = (Table1)session.CreateCriteria(typeof(Table1)).Add(NHibernate.Expression.Expression.Eq("Id", id)).SetFetchMode("Table2", FetchMode.Default).List()[0]; //where Table2 is the property.

On executing the application, i received that
"Cannot convert type 'Table2' to NHibernate.Collection.Set"
Then i changed
public Table2 Table2
{
}

to
public Set Table2
{
}

Now it says

"could not initialize collection: [MyAssembly.Table1.Table2#1]"

Thanks and Regards,
Padmavathy T.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 08, 2006 5:51 am 
Expert
Expert

Joined: Thu Jan 19, 2006 4:29 pm
Posts: 348
Try

table1.hbm.xml

<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
<class name="MyAssembly.Table1, MyAssembly" table="Table1">
<id name="Id" column="Id" type="int">
<generator class="assigned"/>
</id>
<property name="BName" column="BName" type="string" length="20"/>
<many-to-one name="IssuedTo" class="MyAssembly.Table2, MyAssembly" column="IssuedTo"/>
</class>
</hibernate-mapping>

table2.hbm.xml

<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
<class name="MyAssembly.Table2, MyAssembly" table="Table2">
<id name="UId" column="UId" type="int">
<generator class="assigned"/>
</id>
<property name="UName" column="UName" type="string" length="25"/>
<set name="Table1" cascade="none" inverse="true">
<key column="IssuedTo"/>
<one-to-many class="MyAssembly.Table1, MyAssembly"/>
</set>
</class>
</hibernate-mapping>


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 08, 2006 5:54 am 
Expert
Expert

Joined: Thu Jan 19, 2006 4:29 pm
Posts: 348
gert wrote:
Try
<many-to-one name="IssuedTo" class="MyAssembly.Table2, MyAssembly" column="IssuedTo"/>


Sorry, as You did have property

public Table2 Table2, then

<many-to-one name="Table2" class="MyAssembly.Table2, MyAssembly" column="IssuedTo"/>


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 08, 2006 6:47 am 
Newbie

Joined: Tue Feb 07, 2006 9:41 am
Posts: 6
Hi,

Its working well, thanks for your help. But still got one more issue.

When I tried to display the records in the table 'Table1' using 'createcriteria' method, it returns 'Issued To' as 0, always.

I changed the things in .hbm.xml files as you have mentioned.

Thanks and Regards,
Padmavathy T.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 08, 2006 7:20 am 
Expert
Expert

Joined: Thu Jan 19, 2006 4:29 pm
Posts: 348
Well, as the IssoedTo property of Tbale1 class is mentioned in hbm map, it is transient.
If You really need IssuedTo int property in Table1, then You have couple of options. But in normal situation You should not deal with Id refrences at class level... as You have object references already.

1. as suggested earlier by NHibernate:
Padmavathy wrote:
{"Repated column in mapping for class Core.Table1 should be mapped with insert="false" update="false": IssuedTo"} exception


add a line to table1.xml.hbm:

<property name="IssuedTo" column="IssuedTo" type="int" insert="false" update="false" />

alternatively
2. Make the IssuedTo (or Table2) property calculated, with code:

public int IssuedTo
{
get { return this.Table2.UID; }
// set { this.Table2 = (table2)someSession.GetObject(typeof(table2), value); }
}


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 08, 2006 7:33 am 
Newbie

Joined: Tue Feb 07, 2006 9:41 am
Posts: 6
Hi,

Thank you so much. Its working now !!!

Thanks and Regards,
Padmavathy T.


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