-->
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.  [ 6 posts ] 
Author Message
 Post subject: 2 classes map to same table (one read-only). Advice Please
PostPosted: Thu Dec 11, 2008 8:52 pm 
Beginner
Beginner

Joined: Fri May 30, 2008 3:57 pm
Posts: 26
NHibernate 1.2
.Net 3.5
SQL Server 2005


I have two classes that map to the same table and one of them is read-only. When creating the factory NHibernate throws an exception about the duplicate mapping, even with the add auto-import="false" added to both configuration files.

Is there a way to do this?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 12, 2008 4:19 am 
Expert
Expert

Joined: Thu Dec 14, 2006 5:57 am
Posts: 1185
Location: Zurich, Switzerland
Can you post your mappings and tables ?

_________________
--Wolfgang


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 12, 2008 1:42 pm 
Beginner
Beginner

Joined: Fri May 30, 2008 3:57 pm
Posts: 26
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" auto-import="false">
  <class name="Services.SharedNhibernate.PlantModel, SharedNHibernateModels"
         optimistic-lock="version"
         table="plants">

    <id name="id" column="id" type="Byte" >
      <generator class="identity" />
    </id>
    <version name="optimisticLock" column="optimistic_lock" type="Int16" />

    <property name="name" column="name" type="String" length="50"/>

    <property name="UTCOffset" column="utc_offset" type="Int16" />

    <property name="createdOn" column="created_on" type="DateTime" />
   
    <property name="lastEditedOn" column="last_edited_on" type="DateTime" />
    <property name="lastEditedBy" column="last_edited_by" type="Int32" />

  </class>
</hibernate-mapping>



Code:
<?xml version="1.0" encoding="utf-8" ?>
            <!-- This entity is read only -->

<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" auto-import="false">
  <class name="Services.User.PlantModel, User"
         mutable="false"
         table="Plants">

    <id name="id" column="id" type="Byte" >
      <generator class="identity" />
    </id>
    <property name="name" column="name" type="String" length="50"/>
  </class>
</hibernate-mapping>


Code:
CREATE TABLE [dbo].[Plants](
   [id] [tinyint] IDENTITY(1,1) NOT NULL,
   [name] [nvarchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
   [utc_offset] [smallint] NOT NULL,
   [created_by] [int] NOT NULL,
   [created_on] [datetime] NOT NULL,
   [last_edited_by] [int] NOT NULL,
   [last_edited_on] [datetime] NOT NULL,
   [optimistic_lock] [smallint] NOT NULL,
CONSTRAINT [PK_Plants] PRIMARY KEY CLUSTERED
(
   [id] ASC
)WITH (PAD_INDEX  = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]



Both configurations map to the same table, but one of them is read-only. I'm changing the way I'm handling factories so I only create it once, which means I need to include all of the configurations. There are a few other approaches I'm going to try if I can't do this with NHibernate (but I'm hoping I can).

Also, I've been moving all of my NHibernate models into a separate DLL specifically for them rather than littering them throughout the services. This is my first project with NHibernate and I've come to the conclusion that it's a better way to operate in general. At least I think so, I'm interested in your opinion on the matter.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 12, 2008 1:54 pm 
Expert
Expert

Joined: Thu Dec 14, 2006 5:57 am
Posts: 1185
Location: Zurich, Switzerland
Afaik, it shouldn't be a problem to map the same table multiple times. Maybe it's a problem that the classname is already mapped. Try a different classname just to rule that out.

_________________
--Wolfgang


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 12, 2008 4:33 pm 
Beginner
Beginner

Joined: Fri May 30, 2008 3:57 pm
Posts: 26
yep, tried it and changing the name of the models worked.


Thanks :)


Top
 Profile  
 
 Post subject:
PostPosted: Sat Dec 13, 2008 7:32 am 
Expert
Expert

Joined: Thu Dec 14, 2006 5:57 am
Posts: 1185
Location: Zurich, Switzerland
But still sounds like a bug to me. You may want to open an JIRA issue about this.

_________________
--Wolfgang


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