nhibernate-mapping

How does one map multiple classes to one table through NHibernate?

I have an Employee class with a Name property of class Name and a Contact property of type Contact. The Name class has two string properties: FirstName and LastName and the Contact class has properties like PhoneNumber and EmailAddress. All of the data is found in one table and assume that it cannot be changed. What would my maps look...

Are Denormalized Updates Possible With NHibernate Without Using a Stored Procedure?

I'm pondering the use of NHibernate on a project that has a database with some degree of planned denormalization (planned by the DBAs). Reading from one set of tables and mapping one column to one property is not a problem. However when updating I'd have to map one property back to the original column in the original table plus update a ...

Hibernate Next/Previous Sibling Mapping

I'm using nHibernate to map an object very similar to .NET's System.Web.SiteMapNode. In order to keep my object similar to this .NET object I would like to have it contain a ParentNode, PreviousSibling, NextSibling, and ChildNodes complex properties. The table looks somewhat like this and is open to be changed: ID (int) Title (string...

Unmapped Columns in NHibernate?

I'm working with a legacy database in Oracle and some of my tables have columns that are set to NOT-NULL that I don't want in my domain model, but, obviously, I need to specify somewhere that at least some default value is saved to the database (eg a Groups table may have a "Indentation" column thaqt always expects a char(8) value). How...

NHibernate/Fluent NHib: How to use UserTypes for Ids?

I have columns in my Oracle db that I use a TrimmedStringUserType for to trim text from char(x) columns. The db has natural keys in many tables, so I'm using Assigned Ids. Many of these are char(x) columns. How, using Fluent NHibernate (or even in the xml mapping) would I use this usertype to ensure that the Ids are trimmed? ...

NHibenate cascade problem.

Hi I'm having a problem updating child objects in the following scenario. The mappings are as follows: Parent: Calendar <bag name="defaultCategories" inverse="true" lazy="false" cascade="all-delete-orphan"> <key column="parentID" /> <one-to-many class="DefaultCategory"/> </bag> Child: DefaultCatergory <class name="Def...

(Fluent) NHibernate : One entity composed of fields from different tables

Is there a way of writing an NHibernate mapping so that you can have an entity that is composed of fields from different DB tables? For Example is I have a Person and Address table, I want address fields to appear in my person object. I want an entity like this: public class person { public virtual Guid Key{get; set;} public v...

NHibernate mapping after a normalisation

Please help me - I'm new to NHibernate and I cannot seem to find what I'm looking for. I have two tables in a database: Fund and FundBalance. A Fund can have many FundBalances and a FundBalance has only one Fund. In C#, there is only the FundBalance class. Columns from the Fund table joined with columns from the FundBalance table need ...

Is it possible to set a default value on a property with NHibernate

I'm using Fluent NHibernate for my mappings and the SchemaExport class to the database schema. Is it possible with NHibernate to set a default value for a property/column in the generated database schema? ...

NHibernate 2.* mapping files: how to define nullable DateTime type (DateTime?)?

I know one of the breaking changes with NHibernate 2.* is that the NHibernate.Nullables are no longer supported. Therefore, what do you use in your mapping file to map the nullable DateTime? type? For i.e.: Understandably doesn't work: <property name="CreateDate" column="CreateDate" type="DateTime?" not-null="false" /> And no longer ...

Mapping Siblings in NHibernate

I've been trying to build a SiteMapNode styled object with NHibernate mappings. The goal is to mimic the ASP.NET SiteMapNode object so that a custom provider can be built using NHibernate for a dynamic backend. The issue I'm running into is the way the tree nature of a site map. The ASP.NET object has a next and previous sibling obj...

NHibernate mappings when self-join relationships have additional properties

How do you map a class to other instances of the same class when that relationship has properties itself? I have a class called Person which is mapped to a table Person PersonID PersonName PersonAge ---------------------------------- 1 Dave Dee 55 2 Dozy 52 3 Beaky ...

Conditional Relations in NHibernate

I have a table that needs relations to 2 tables, according to ObjectType column. For example if ObjectType=1 then column Object should point to TABLE1, and if ObjectType=2 then point to TABLE2. Can I accomplish this in NHibernate mappings or as Fluent NHibernate? If not will you suggest me using same Interfaces for both Table classes?...

Nhibernate: Make Many-To-Many Relationship to Map as One-To-One

I have two items A and B, which have a uni directional one-to-one relationship. (A has one B) In the database these are represented by ATable and BTable, and they are linked together by ABTable. (From the database setup it appears there is a many-to-many relationship but there is not, it was done this way for normalization reasons). ...

NHibernate DataTypes - NoYes Boolean

What is the best way to get the reverse behavior of the YesNo Boolean type in NHibernate mapping? I want 'Y' to mean false and 'N' to mean true. Is there a NoYes type? Do you write a custom type? something really easy? This issue of needing to reverse the Boolean exists on at least one field on over 40 tables. Trying to adapt to a leg...

Generate table indexes using Fluent NHibernate

Is it possible to generate table indexes along with the rest of the database schema with Fluent NHibernate? I would like to be able to generate the complete database DDL via an automated build process. ...

Hibernate: How to map a *.hbm.xml file in a different folder?

I have some *.hbm.xml files that are placed in the same folder at the hibernate.cfg.xml file. Now, I want to map some other *.hbm.xml files that are in a subfolder of this folder. How could I do it? Thanks! here's part of my hibernate.cfg.xml: <hibernate-configuration> <session-factory name="MySessionFactory"> <...

Nhibernate - query with join table without relationship

Hi all: I was wondering if anyone has tried to do this in NHibernate. I have the following tables (simpify version). CITY: city (varchar2) (PK) province (varchar2) (PK) CITY_TL: city (varchar2) (PK) province (varchar2) (PK) lang (char (2)) (PK) LOCATION: location (varchar2) (PK) some other column. As you can see, there are no relat...

Fluent NHibernate objectified relationship mapping

Hi there! Looking for an answer on how to configure NHibernate to support my scenario, an many-to-many map with an objectified relation. I have a colection of Person:s with relations to other Person:s. Each of the relations have an attribute specifying what type of relation they have. In an RDB this is done by using a many-to-many tabl...

NHibernate - is there any point in setting length attribute for properties/columns?

typically definition of property/column looks like this: <property name="DocumentSummary" column="DocumentSummary" length="100" type="String"> <column name="DocumentSummary" /> </property> I was assuming that NHibernate will validate data using length attribute before inserting/updating a row. Unfortunately it seems to be invalid a...