nhibernate

NHibernate Map many-to-many join table

My database structure looks something like this: Person Id Name FieldA FieldB Phone Id Number PersonPhone PhoneId PersonId IsDefault My NHibernate mappings for the Person and Phone objects are straight forward, its the PersonPhone I'm having difficult with. I want to have a collection of PersonPhone objects as a pr...

Mapping Dictionarys containing a List

Hello, I'm trying to map a Dictionary containing Lists. I have the following set of tables: CREATE TABLE Item(id) CREATE TABLE Filter(id) CREATE TABLE FilterType(id) CREATE TABLE ItemFilter( item REFERENCES Item(id), filter REFERENCES Filter(id), filterType REFERENCES FilterType(id) ) and I want to do this mapping: class Item...

nHibernate: Saving new parent object while creating a child object

I am trying to save a record which has a many-to-one property mapping. I attempt to assign a newly created parent object here (or use an existing, but that works fine) but I get an error when it tries to add the ID of the parent object to the child's table. Saying it cannot add NULL to the table, which is true, but I thought nHibernate w...

One-to-Zero-Or-One mapping - eager load results in multiple lazy load when zero

Iam trying to do some Eager loading with some entities that have a reference to one or zero elements. The problem arises when it refers to zero element. I have the following class Car { int id string name Driver driver } class Driver { int id string Name } The Driver gets loaded using References(x => x.Driver).ColumnName("driv...

Fluent NHibernate Joined-Subclass Problems

I have this class public class Address:Entity { public virtual string Address1 { get; set; } public virtual string Address2 { get; set; } public virtual string City { get; set; } public virtual string State { get; set; } public virtual string Zip { get; set; } public virtual string Phone { get; set; } public ...

How to join on none PK/FK columns using HQL?

Using HQL, how do you join on columns (or object properties) that are non PK/FK? I'm reading the docs, and it seems it implicitly is going to join on the PK columns right? https://www.hibernate.org/hib_docs/nhibernate/html/queryhql.html ...

AutoMapping a Composite Element in Fluent Nhibernate

I'm trying to get the AutoPersistence model to map several composite elements. However, it seems that either I end up mapping it as an entity, dropping down to manual mapping or it just doesn't plain work. Here's some code that demonstrates my problem: using System; using System.Collections.Generic; using FluentNHibernate.AutoMap; usi...

How to do a "null-table" select in NHibernate?

In other words how do you do something simple like this: select 1 Or more specifically in the particular problem I'm dealing with, something like this: SELECT (case when exists (<subquery>) then 1 else 0 end) AS result So in short is there a way in NHibernate to do a select without having it generate the "FROM table" clause? Thank...

Hibernate NHibernate - Native SQL

Trying to delete an unmapped class/record via the NHibernate sql api. But can't seem to get it working. Does anything look wrong with this? session = NHibernateHelper.GetCurrentSession(); tx = session.BeginTransaction(); using (tx) { session.CreateSQLQuery("DELETE FROM tb_category WHERE parentID = :p...

NHibernate property formula filter

Hi, I have a following class: MyClass public virtual int Id { get; set; } public virtual int Code { get; set; } public virtual int Description { get; set; } public virtual int Name { get; set; } with the following mapping: <?xml version="1.0" encoding="utf-8" ?> <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" namespace="TestAp...

NHibernate "database" schema confusion [.\hibernate-mapping\@schema]

I'm using NHibernate primarily against an MSSQL database, where I've used MSSQL schemas for the various tables. In my NH mapping (HBM) files, I've specified the schema for each table in the mapping as follows: <?xml version="1.0"?> <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" auto-import="true" ...

NHibernate StaleObjectStateException when using version optimistic locking for an object with a one-to-many relationship

I am using NHibernate and ASP.Net using a session per request as suggested in the best practices article by Billy McCafferty (sorry, I cannot include the link). I have used this successfully with version optimistic locking, saving updated objects in the HTTP Session object and reattaching to the NHibernate session using the SaveOrUpdate...

Can I "join" two tables into one class whilst also creating many-to-one relationships using NHibernate?

We have a legacy database schema which I've tried (unsuccessfully) to map with NHibernate. To give a simplified example, say I want a Person class whose first name comes from the "Person" table, but their last name comes from the "Person2" table. The "Person" table also has the Id of the person's Car and I want my Person class to have a...

Getting specific number of rows from db using nhibernate

How can I get specific number of records from nhibernate like 10 or 15 at a time instead of all records. I actually got the answer using criteria.setmaxresults(). But my question is how can I get first 10 records, then next 10 records and then.... next 10....... ...

nhibernate many-to-many mapping - additional column in the mapping table?

hi I have following mapping definitions: <class name="Role" table="Role" optimistic-lock="version" > <id name="Id" type="Int32" unsaved-value="0" > <generator class="native" /> </id> <property name="RoleName" type="String(40)" not-null="true" /> <bag name="UsersInRole" generic="true" lazy="true" cascade="all"...

NHibernate - LazyLoad one-to-zero

Hi Iam struggling with NHibernate and its lazyload. I have a structure which I simplified but it show my issue. Class Shift { int ShiftID; DateTime ShiftStart; Employee Employee; } Class Employee { int EmployeeID; string Name; } Data: ShiftData ID SHIFTTIME EmployeeID (int) 1 ...

How to use ICriteria with Enum properties in NHibernate

Hi I want to write a FindByExample(object o) method. So I tried this: public IList<T> FindByExample(T o) { return Session.CreateCriteria(typeof(T)).Add(Example.Create(o)).List<T>(); } (It's in a generic class) It should work fine, but if T has a property of an enum type, it throws this exception: "Type mismatch in NHibernate.Cri...

NHibernate Version conflicts

Do I need to create my own build of nHibernate and tools if i want to use the following frameworks in 1 project. nHibernate nHibernate Validators Fluent NHibernate xVal NHibernate Provider nHibernate Linq I am getting "Could not load file or assembly 'NHibernate," errors which I believe is because each framework is built against a ...

NHibernate Interceptor Auditing Inserted Object Id

Hi, I am using NHibernate interceptors to log information about Updates/Inserts/Deletes to my various entities. Included in the information logged is the Entity Type and the Unique Id of the entity modified. The unique Id is marked as a <generator class="identity"> in the NHibernate mapping file. The obvious problem is when logging an...

can i write one hbm file for two classes

hi, i have two tables both are related with primary-foreign key ralation and i have two corrosponding pojos now can i write single property file(hbm) for both classes if so can any one please give sample typical hbm file ...