nhibernate-mapping

Is there a way to map a one-to-one with a where clause?

Please excuse my ignorance on the topic, as I am relatively new to Hibernate / NHibernate, but I have encountered a mapping I can't figure out: This is what my database table looks like: <bincontents> <id>5873715</id> <title>Video Title</title> <sortorder>0</sortorder> <itemid>23079</itemid> <itemtype>VIDEO</itemtype> <...

Trouble using nHibernate 2.0's Session.Get<T> on a class with a composite-id

I'm having trouble with something that (I think) should be simple, but can't find any clear info. In the scenario where I have three tables, describing a domain where a person can have more than one job: Person - has PersonId, Name Job - has JobId, JobName PersonJob - has PersonId, JobId, YearsOfEmployment Note: In my object mode...

Many-to-many mapping with extra columns in join table

Here is the domain that I wish to have: public class Person { public int Id { get; set; } public IList<AcquiredCertificate> AcquiredCertificates { get; set; } } public class AcquiredCertificate { public Person Acquirer { get; set; } public Certificate Certificate { get; set; } public DateTime DateAcquired; } public class Certific...

nHibernate 2.0 - mapping a composite-id *and* many-to-one relationship causes "invalid index" error

I have a problem. Imagine this data model: [Person] table has: PersonId, Name1 [Tag] table has: TagId, TagDescription [PersonTag] has: PersonId, TagId, IsActive Since [PersonTag] isn't just a simple many-to-many join table, i have all three entities created in nHibernate (exactly like they are in the data model). PersonTag, therefor...

How do you map a component that is also a primary key in NHibernate hbm xml (or in a fluent-nhibernate class map)?

I'm trying to figure out how to map a component as a primary key in nhibernate and if possible in fluent nhibernate as well. The component in question is a unique set of 3d coordinates, here's the object: public class SpaceLocation { public virtual SpaceCoordinate Coordinates { get; set; } public virtual SpaceObject AtLocation...

How do you map an enum as string in fluent nhibernate?

Is it possible to map an enum as a string using Fluent Nhibernate? ...

How can I query a SQL 2005 XML field with NHibernate?

My Microsoft SQL Server 2005 database contains a table that has an XML field that has some important metadata, and under normal SQL I could run the following query and get a list of items which don't have UPC codes set... Unfortunately I'm having a hard time re-creating this query using NHibernate's Criteria API: SELECT [Id],[meta].valu...

Fluent Nhibernate mapping inner join on 3 tables

Datastructure is: Table[Questionnaire] the top node Table[QuestionGroup] just a grouping for heading etc Table[QuestionnaireQuestion] mapping [Question]<->[QuestionGroup]s many to many relationship and the [Questionnaire]<->[Question]s many to many relationship Table[Question] One question can exist in many questionnaires/questiongro...

NHibernate: Using Fluent Nhibernate to save child objects

Hello, In my system, I have two entities - ShoppingCart and ShoppingCartItem. Fairly generic use-case. However, when I save my ShoppingCart, none of the items are being saved to the DB. Within my object, I create a new ShoppingCart object. ShoppingCart cart = CreateOrGetCart(); I then add an existing Product which I got from the data...

Mapping one to many collection with Foreign Key to Foreign key

I'm mapping a legacy database with nhibernate and having some problems with mapping a realation. The two classes look like this public class Questionnaire { public int Id {get; set;} public string FormCode {get; set;} public IList<Question> Questions {get; set;} } public class Question { public int Id{get; set;} pu...

Hibernate/NHibernate mapping file editor

I'm looking for an editor that has the help from http://www.hibernate.org/hib_docs/nhibernate/html/mapping.html built in, and allows simple editing of the XML files in a GUI fashion. I realise there's CodeSmith and MyGeneration, but from what I remember these only go one way, and don't allow editing existing HBM files. ...

NHibernate - Mapping ID to a DB2 Identity

I'm newish to NHibernate, and am attempting to wire up to a DB2 table through the ISeries provider. The table has a BIGINT primary key that is auto generated as an identity. I've tried several values for the generator property of the id in my mapping file, and haven't had any success. The table def looks like so (field names changed):...

Is it one-to-one or Component ? Nhibernate Mapping

Assume that I have Person and Address Classes and they have different tables in DB. One Person can have one Address Class in it. This is the important part for me. One Person can have only one Address as it s child element and i want to keep them in different tables in DB. Normally i know that i need to hold them in the same table, but...

NHibernate generic component

How can I create generic component mapping in NHibernate, I have a class Pair{virtual T First{get;set}, virtual T Second{get;set;}}, I am trying to map it with something like this which is not working ...

Mapping items-itemtags-tags tables with nhibernate

Lets say i have this database design: Items Id Name Desc ItemTags ItemId TagId Tags Id Tag And i want to map it to the following class class Item int Id string Name string Desc IList<string> Tags Please note that I don't want to declare class Tag, i just want the Item class to have list of strings that repre...

Strange NHibernate exception

Hi I'm getting a strange NHibernate exception when I try and create a SessionFactory. I've narrowed down the exception 'Unable to cast object of type 'NHibernate.Mapping.Bag' to type 'NHibernate.Mapping.IKeyValue' to the following mapping on the Company object: <bag name="Images" cascade="none"> <key column="CompanyId" property-ref...

How to map Items which its SubItems are in the same Table with Nhibernate?

Hi, I am trying to build a messaging system and for this i have the table definition below Message Id From To Body ParentId // Subcollection, i want to get Asnwers (Message.ParentId== Message.Id) IsRead and i have this in the Message.cs IList<Message> Answers; I have tried this but it gives me all the messages and all the answers...

NHibernate - map same entity to different tables within the same database.

Lets say we have an Employee entity composed of a few other entities, such as a one-to-many addresses and contacts, and a few fields (name, age, etc). We mapped this entity out and can use it just fine, saving each piece out into "Employee", "EmployeeAddresses", and "EmployeeContacts" tables. However, we use pretty much all of this empl...

NHibernate - What kind of association(s) is this?

I'm having some trouble getting NH to persist my object graph. I have (something like) this: /*Tables*/ TABLE Parent ParentID PK LastEventID NULL TABLE Event EventID PK ParentID FK NOT NULL //Model Classes public class Parent { public List<Event> Events; //Inverse //Denormalized bit public Event LastEvent; ...

NHibernate - not-null property reference a null or transient value

I'm getting this exception (Full exception at the bottom): NHibernate.PropertyValueException was unhandled by user code Message="not-null property references a null or transient valueClearwave.Models.Encounters.Insurance.Patient" Source="NHibernate" EntityName="Clearwave.Models.Encounters.Insurance" PropertyName="Patient" I've don...