nhibernate

How do I configure NHibernate (or Fluent NHib) to add a table name prefix to all table names?

In the current application I'm developing I'm using fluent nhibernate to configure nhibernate for use as an ORM. I want to be able to add a prefix to all the table names used in the application, so that if I use a database that is already servicing another application, there are no naming conflicts between the two applications. So for...

NHibernate queries return multiple copies of the target objects

I have two classes mapped in NHibernate: Dragon and its subclass FierceDragon, with a few FierceDragons stored stored in a table called Dragons. When I run an HQL query like from Dragon... I get back two objects per row: the expected FierceDragon and an ordinary Dragon that's a copy of the FierceDragon (insofar as is possible; naturally...

Find NHibernate association when NHibernate.ObjectDeleteException is thrown

My data model has some complex relationships where I have to remove objects from associations before I delete them from NHibernate. However, I am currently getting NHibernate.ObjectDeleteException {"deleted object would be re-saved by cascade (remove deleted object from associations)[Model#12344566]"} I'm sure the issue is with my cod...

Nhibernate question about extension object without changing the original mapping

Say i have a cms with only one object called Article (for the sake of this example) with an ID and a title. This CMS implementation becomes part of a framework and is used as a library: e.g. CMSFactory.CMS.SaveArticle(a); The problem is that depending on the project requirements an article object may have more fields such as SomeDate. I...

NHibernate: is there limitation of batch-size to 10 items?

Hi! I am having a problem with NHibernate (SQL Server 2000, if it matters). It seems like NHibernate uses batch-size equal to 10 even if I specify 500 (but if I specify size less than 10, say 3 - it uses 3) <bag name="RiskTypes" table="CalculationQuery" lazy="false" batch-size="50"> <key column="CalculationID"></key> <many-to-many...

Custom exception using NHibernate ISqlExceptionConverter

Hi everybody. I need to register custom exception for NHibernate dialect. I have implemented and registered ISqlExceptionConverter, as shown in NHibernate tests. But when exception in code throws, it is not converted. My conversion code even does not call. My code is really simple: try { using (ISession sess = OpenSession()) ...

Field in mapped entity required

Hi I'm not sure if my problem is solvable in a more or less comfortable way. There is a class Person which has mapped 'hasOne' a participant. The person has a birthday but this field is not required on the person itself. But if I would like to add a participant to the person then the birthday is required. How to get rid of this mo...

Why is NHibernate deleting immutable class instance?

I'm trying to migrate an app from NHibernate 1.x to 2.1, and I've noticed something odd: my immutable objects are being deleted in my integration tests. For example, this test used to pass: [Test, ExpectedException(typeof(NHibernate.HibernateException))] public void DeleteExistingInstanceThrows() { // Note: NHib transaction is opened/...

NHibernate: can I prevent setting of auditing fields from making an object dirty?

A common thing that many people do with NHibernate is setting of auditing fields (e.g. CreatedDate, LastModifiedDate) when they save an entity. There are lots of blog posts on how to do this sort of thing using NHibernate events. This one uses the SaveUpdate event: http://www.codinginstinct.com/2008/04/nhibernate-20-events-and-listener...

Delete column in SQL Server after a period from creation

I am working with sensitive/private files stored in SQL Server as VarBinary(MAX). Is there a way to tell the database or nHibernate to nullify the column after a period of time after its creation. ...

NHibernate - Query by Example - Subquery

Hello, I know there are MANY ways to achieve the following in NHiberante - i am not interested in other scenarios. What I am wondering is if it is possible to automatically generate a subquery using a many-to-one relationship and a query by example in NHibernate. My setup is as follows: public class Customer { public virtual int ID...

Best approach for building NHibernate DTO's

I'm new to NHibernate (and ORMS) and trying to come to grips with the myriad of different options it presents. For reference, I'm using Fluent NHibernate with seperate business objects which in turn use DTO's purely for data access. My application architecture must support both windows and web "front ends". My quandry is one of general ...

NHibernate hql - order by find_in_set with parameter

In one of my queries I have to order the result by a defined order. It looks like this: public IList<Media> CollectionFor(int[] uidArray) { Sess.CreateQuery("... where m.Uid in (:uidList) order by FIND_IN_SET(m.Uid, '" + Misc.JoinNumberArray(uidArray) + "')") .SetParameterList("uidList", uidArray) } ...

Hilo in c# console app with nhibernate

Hello! Having a console app which which many will start over and over again and using hilo. Everytime the app is started and the sessionfactory is rebuilt the hilo columns (next_hi) will be increased and a reserved space with ids will be lost. Have anybody had any experience with this? Could't that be a nice feature for the hilo-gener...

Mapping to an element of an array

I have a class Parent wich contains an array of 3 Child class objects (Child[] ChildArray). I have a Database Table MyTable with fields [FLD_01], [FLD_02], [FLD_03]. How do I map [FLD_01] to ChildArray[0], [FLD_02] to ChildArray[1] etc? ...

Fluent Nhibernate over legacy database in oracle

Hello , I am trying to connect to the existing db in oracle with fluentmapping . I got Mapping over CUstomer public CustomerMapping() { Not.LazyLoad(); Id(x => x.Cst_Recid).GeneratedBy.Increment() ; } and i am trying to create session public static ISessionFactory CreateSessionFactory() { retur...

NHibernate query cache and WCF

I've enabled query cache for one of my queries, it works fine (query result is taken from query cache and entities from second level cache) when I run a test or a console application. However, if I run the same queries through a WCF service, the cache is never hit. I've also checked the logs in both cases and they are practically ident...

Fluent NHibernate Composite Id Issue...

I have the following mapping class that requires the use of a composite id. The issue I am having is that the exposed related entities (OrganizationSurvey) and (Section) are both coming back as null. However, the entities do exist in their respective tables... What am I not seeing or doing wrong..?? public SectionResponseMap() ...

NHIbernate DataReader Equivalent?

Hey guys, I'm somewhat new to NHibernate, so this question may be a no-brainer. Anyway, I'm replacing a project at work that uses ADO.NET that will now be using NHibernate(With LinqToNhibernate). This has worked fine so far, but I've run up against a function that needs to search through a large amount of data(about 200,000 records, te...

NHibernate many-to-many using foreign key different to primary key

When creating a one-to-many relationship in NHibernate it is possible to use the "property-ref" attribute to specify that the relationship occurs on a different column to the primary key. This is sometimes useful for legacy databases. It seems that the same feature should be available for many-to-many relationships, but I can't find it ...