nhibernate

Fluent NHiberante - Many To Many Relation

I have Product and Category tables in database. One product can have many categories. One category can have many products. So, I have a third table as ProductCategory, which has ProductID and CategoryID. In Fluent NHibernate, what does the mapping class should look like? For example, For ProductMap class is it correct: HasMany(x =>...

Enum parsing doesn't seem to work with Fluent NHibernate

Hi all I have a data access class with an Enum called Salutation: public enum Salutation { Unknown = 0, Dame = 1, etc Mr = 5, etc } I am peristing the class with NHibernate, and up until this morning I was using .hbm.xml files for mapping. However, I've now switched to using Fluent NHibernate, but loading ins...

NHibernate show-sql - why is the SQL shown invalid?

Hi all I love the feature in NHibernate that shows the generated SQL. But when I pasted it into SQL Server Management Studio, I realised it's not actually valid! Here's an example: SELECT person0_.PersonId as PersonId1_0_, person0_.Title as Title1_0_, person0_.FirstName as FirstName1_0_, person0_.MiddleNames as MiddleNa4_1_0_, person0...

Linq to nhibernate question

Hi, I'm trying to create a query using linq 2 nhibernate which generate a sql like: select * from table where id in (1, 2, 3, 4) At the moment I have this code: var vouchers = Session.Linq<Voucher>() .Where(x => campaignIds.Contains(x.VoucherGroup.Campaign.Id)) .ToA...

Castle Activerecord object doesn't refresh

I am using castle active record, I load an enity using the .Find() method, after updating the database i call entity.Refresh() but the entity doesn't refresh, the data that i changed in the database is not reflected in the state of the entity. I am at a total loss as to how to get this to work. ...

Or statements in criterion

I have a list of orders, which are connected to a user-table. Each order can contain multiple users. I then have a search area where an admin can search through all orders by searching for e.g. a last name. If there is done a search for e.g. Smith, all orders where a user named smith should be shown, but how is this done with NHiberna...

Or statements in criterion

I have a list of orders, which are connected to a user-table. Each order can contain multiple users. I then have a search area where an admin can search through all orders by searching for e.g. a last name. If there is done a search for e.g. Smith, all orders where a user named smith should be shown, but how is this done with NHiberna...

To cascade or not to cascade? ("object references an unsaved transient instance" error)

Hello, gentlemen! First, I've tried to ask the similar question yesterday (http://stackoverflow.com/questions/3255407/nhibernate-many-to-many-relationship-question-can-select-cant-update), but after a debugging night hopefully I can rephrase a question the better (right?) way. If I am doing something wrong by that - please tell - I'll er...

NHibernate - Person objects at different nodes of object graph are seen as being the same

[Edit: forget this post - I'm not sure what NHibernate is doing, but it's not doing what I just said it's doing. Please ignore.] I have a 'parent' class in the object graph called Case. Here's a snapshot of Case: public class Case { public virtual Person Deceased {get;set;} public virtual IList Executors { get; set; } public Ca...

NHibernate, Oracle and sql instrumentation

Hopefully I can express this in a coherent and meaningful way: Two of our DBA's came up to me today after an email I sent explaining why we were using NHibernate and the benefits of an ORM framework. They have been pushing hard for refactoring our stored procs to include instrumentation like this: BEGIN DBMS_APPLICATION_INFO.set_module...

NHibernate one-to-many mapping does not populate the bag

I have a simple object model of a header with multiple detail lines. I have mapped a bag property on the header object to the line class and also put a header property on the line class to set the two way relationship. When I run my tests, using NHibernate Profiler I can see that the query is being performed, and the header and lines ar...

(NHibernate) PerformSaveOrUpdate event not saving correctly

I have a custom event listener being added (fluently) to my configuration using: .ExposeConfiguration(c => c.SetListener(ListenerType.SaveUpdate, listener)) My listener just captures before a save or update and handles audit fields (CreatedBy, Modified By, etc.) protected override object PerformSaveOrUpdate(SaveOrUpdateEvent sender) ...

NHibernate - does NHibernate recognise object equality and change is save behaviour accordingly?

Hi all Let's say you have two classes, Person and Address. Person has a reference to Address like this: public class Person { public virtual Address Residence {get;set;} } Address has an override of .Equals which determines whether two Address instances represent the same physical address (by comparing postcode and first line, say...

How do i transform a HQL result to List<T> where T is a mapped class.

I have this nhibernate query: var q = NHibernateSession.Current.CreateSQLQuery ( @"SELECT LastestEvents.* FROM ( SELECT DISTINCT SbQcontainer.Container FROM HistoricEvents SbQc...

Nhibernate createsqlquery from different db won't persist

I first try and pull the customer from the db, but if my customer doesn't exist, then i make a sql call another db on the server to get the information. I'd like to then save the customer info in my db. The Session is currently hooked up to my db. var customer = Session.Linq<Customer>().FirstOrDefault(x=>x.customernumber == cusotmerNu...

NHibernate cascade update/insert

I have a Case class which exposes a Person object as follows: public class Case { public virtual Person Deceased {get;set;} } I have a PersonalAsset class which also exposes a Person: public class PersonalAsset { public virtual Person Owner {get;set;} } Assuming I write the following code within an ISession: Case case = new Ca...

Fluent NHibernate fails on Creating Session Factory.

I have used SQL Server 2008 configured in hibernate.cfg.xml file and everything worked fine. Once I tried to use SQLite in memory.. I have having the following issues... hibernate.cfg.xml <?xml version="1.0" encoding="utf-8" ?> <configuration> <hibernate-configuration xmlns="urn:nhibernate-configuration-2.2" > <session-factory> ...

Refreshing an entity throws an NHibernate.UnresolvableObjectException

Hello all, The entities and mappings I'm talking about in this question can be found here :) Here is the context: I have a parent view-model which helps to manage some entities, and which has its own session. From this VM, I open another view-model (with its own session too), do some changements to the entity (add and/or remove child...

NHibernate how to join to table twice in HQL

public class Case { public int Id { get; set; } public string Number { get; set; } public Employee Employee { get; set; } } public class Employee { public int Id { get; set; } public string EmployerIdentifier { get; set; } public Case Case { get; set; } } There is a one to one releationship between Case and Emp...

NHibernate SaveOrUpdateCopy won't insert entity with CompositeId

I have an entity with a CompositeId that won't insert new rows to the database using SaveOrUpdateCopy. The INSERT statement generated by NHibernate is populated with "?" for the value of every field. It inserts fine with SaveOrUpdate, it updates fine with either SaveOrUpdateCopy or SaveOrUpdate, and any entity without a CompositeId ins...