nhibernate

NHibernate/ActiveRecord - Any way to map to a foreign key column only?

I'm using Castle ActiveRecord, but this question applies to NHibernate, too, since a solution that works with NHibernate should work for ActiveRecord. Anyway, what I have is an underlying table structure like this: TableA -hasMany-> TableB I have corresponding objects EntityA and EntityB. EntityA has an IList of EntityB objects. Thi...

How do you do a union of two tables in NHibernate?

I need to do a union of two tables using NHibernate and HQL. I have found very little help online, and I want to know if it is possible and if so how? ...

How to force NHibernate to recognize db changes not made through NHibernate

I am implementing NHibernate into an existing web application. However, we have some other processes that do bulk inserting and updating on the database. How can I make NHibernate aware that changes are occurring on the backend db that were not initiated through NHibernate? Most of the info that I have read around NHibernate use in asp....

Filter child collection returned with Aggregate Root using Nhibernate

I'm trying filter the child collection of an aggregate root when loading it with Nhibernate. Load a Customer with all their Orders that have been shipped. Is this possible? ...

Updating many-to-one relationship

I have a User object that has a Country object on it. I map this with a many-to-one tag in the User mapping file: <many-to-one name="Country" column="CountryID" cascade="none"/> How do I update a User's country? At the moment my UI has a dropdown of countries and the ID of the new country is passed to the controller. The controller t...

ordering by collection count in nhibernate

Is there a way of ordering a list of objects by a count of a property which is a collection? For arguments sake let's say I have a question object with a question name property, a property that is a collection of answer objects and another property that is a collection of user objects. The users join the question table via foreign key ...

Named queries with nHibernate

I am having a great deal of trouble getting named queries to work with nHibernate. My latest problem is getting the error message "could not execute query" with no additional information. Are there any complete examples I can download from somewhere because all the tutorials and documentation examples provide code snippits but only tell ...

Copying entities between multiple databases with NHibernate

I have a desktop (winforms) application that uses a Firebird database as a data store (in embedded mode) and I use NHibernate for ORM. One of the functions we need to support is to be able to import / export groups of data to/from an external file. Currently, this external file is also a database with the same schema as the main databa...

Can I flush my NHibernate session and get a new session without committing the transaction?

I'm using Castle ActiveRecord for persistence, and I'm trying to write a base class for my persistence tests which will do the following: Open a transaction for each test case and roll it back at the end of the test case, so that I get a clean DB for each test case without me having to rebuild the schema for each test case. Provide the...

How to persist an enum using NHibernate

Hi, Is there a way to persist an enum to the DB using NHibernate? That is have a table of both the code and the name of each value in the enum. I want to keep the enum without an entity, but still have a foreign key (the int representation of the enum) from all other referencing entities to the enum's table. ...

Creating a NHibernate object and initializing a Set

Hi, I have a Table called Product and I have the Table StorageHistory. Now, Product contains a reference to StorageHistory in it's mappings <set name="StorageHistories" lazy="false"> <key column="ProductId" /> <one-to-many class="StorageHistory" /> </set> And it works, when I retrieve an object from the ORM I get an empty ISet. ...

Is there any way to fake an ID column in NHibernate?

Say I'm mapping a simple object to a table that contains duplicate records and I want to allow duplicates in my code. I don't need to update/insert/delete on this table, only display the records. Is there a way that I can put a fake (generated) ID column in my mapping file to trick NHibernate into thinking the rows are unique? Creatin...

NHibernate Joined Subclass in Separate Assemblies

I have the following solution project structure: Application.Core.Entities Application.Xtend.CustomerName.Entities In the Core project I have an entity Customer defiend. In the XTend project, I have an entity defined that subclasses Customer named xCustomer (for lack of a better name at this time...). The idea here is that w...

Reading Hibernate Properties from Web.config

The C# project I'm working on uses nHibernate and the connection string is in the web.config as a property of a Hibernate element. I need to read the connection string in the installer to get a connection manually without using Hibernate. I know I can use configManager.connectionStrings, but as the connection string is already defined ...

NHibernate architecture?

I'm planning to implement my next project (asp.net MVC) by using nhibernate as an ORM. Since I do not have experience with nhibernate, I wondering how I should organize dependencies between different projects. I've seen something like this as a recommended approach: UI depends on Model, Repositories and NHibernate Repositories depend o...

Best way to convert IList or IEnumerable to Array

I have a HQL query that can generate either an IList of results, or an IEnumerable of results. However, I want it to return an array of the Entity that I'm selecting, what would be the best way of accomplishing that? I can either enumerate through it and build the array, or use CopyTo() a defined array. Is there any better way? I went...

Doesn't NHibernate HQL support "with" keyword?

I'm trying to build a HQL that can left join values from a collection, in order to give me the chance of checking "is null" on it. Taken from the example from hibernate manual: from Cat as cat left join cat.kittens as kitten with kitten.bodyWeight > 10.0 doesn't seem to work in NHibernate, since it doesn't recognize the...

How to use a child object field as part of the compound key in another child in NHibernate

I need to create a new Many-To-One relationship on my User entity which joins against another entity. The problem is the other entity has a compound key of which 1 field is a field in the User entity and the other is a field in another Many-To-One entity. User.Key -> User.NewThing.Key User.SubThing.Key -> User.NewThing.Key Below is th...

How to maintain an object for two nHibernate sessions?

I am building a multithreaded system that works like this: While there are entities: Gets an entity from nHibernate (using the current session) Starts a new thread that will work with this entity* When I start this new thread, it is required to have a new Session, because nHibernate is not thread-safe. I create it, but the entity re...

nHiberante and query optimization

I am using Hibernate as my ORM solution and have a need for a highly specialized object (for performance reasons) to be returned that is unlike my original object. Is it valid to actually set up a second object with its own mapping file so I can set special join fetching and set batch sizes and so forth? Can 2 classes point back to the...