-->
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.  [ 1 post ] 
Author Message
 Post subject: NHibernate One-To-One Mapping
PostPosted: Mon Jun 20, 2011 8:54 pm 
Newbie

Joined: Mon Jun 20, 2011 8:51 pm
Posts: 1
I've an issue using one-to-one mapping. I've searched internet and found many solutions but none was satisfying. Most of the examples carry overhead of storing parent instance in child class.

I want to use only parent Id in child class having foreign key constraint relationship but dont want to keep any parent instance in child.

When I try to load the records from database it throws exception "No row with the given identifier exists [AssemblyName.B#d6455522-6c6d-4582-b6fb-5ac5ce9551f6]". But, the record exists in Table "B" properly.

Any solutions for this issue?

The class structure:

class A
{
public virtual string Id {get;set;}
public virtual B _B_ {get;set;}
// properties......
}

class B
{
public virtual string Id {get;set;}
// properties......
public virtual string ParentId { get;set;} // class A Id
}

The database structure:

CREATE TABLE [A](
[Id] [nvarchar](45) NOT NULL
///....
CONSTRAINT [PK__A__00000000000002C0] PRIMARY KEY CLUSTERED
(
[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

CREATE TABLE [B](
[Id] [nvarchar](45) NOT NULL,
[ParentId] [nvarchar](45) NOT NULL
CONSTRAINT [PK__B__0000000000000B7A] PRIMARY KEY CLUSTERED
(
[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

The mapping:

For Class A:

<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
<class name="A,AssemblyName"
table="A" lazy="true">
<id name="Id" column="Id" type="string">
<generator class="assigned"/>
</id>
<one-to-one name="_B" cascade="all" fetch="join" foreign-key="None" constrained="true"
class="B"/>
</class>
</hibernate-mapping>

<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
<class name="B,AssemblyName"
table="B" lazy="true">
<id name="Id" column="Id" type="string">
<generator class="assigned"/>
</id>
<property name="_Name" column="Name"/>
</class>
</hibernate-mapping>


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.