nhibernate

NHibernate Proxy Creation

I have a class structure like the following class Container { public virtual int Id { get; set; } public IList<Base> Bases { get; set; } } class Base { public virtual int Id { get; set; } public virtual string Name { get; set; } } class EnemyBase : Base { public virtual int EstimatedSize { get; set; } } class Frie...

In hibernate how do I always use db server's timestamp?

Hi, I would like to add db server's timestamp in last_update column of my table. How can I achieve this in hibernate? Thanks ...

Fluent / NHibernate Collections of the same class

I am new to NHibernate and I am having trouble mapping the following relationships within this class. public class Category : IAuditable { public virtual int Id { get; set; } public virtual string Name{ get; set; } public virtual Category ParentCategory { get; set; } public virtual IList<Category> SubCategories { get; se...

NHibernate Linq Provider question

Can anyone answer me what are the differences of Session.Query Session.Linq and Session.QueryOver What I'm really interested in: What would be supported in the future versions. What should I start to use in a clean project. Please tell me your thoughts about these three... Thanks, Zoltán ...

Business entity: private instance VS single instance

Suppose my WinForms application has a business entity Order, the entity is used in multiple views, each view handles a different domain or use-case in the application. As an example, one managing orders, the other one digging into one order and displaying additional data. If I'd use nHibernate (or any other ORM) and use one session/data...

Is there something like a "long running offline transaction" for NHibernate or any other ORM?

In essence this is a followup of this question. I'm beginning to feel that I should give up the whole idea, but I'll give it one more shot. What I want is pretty much like a DB transaction. It should track my changes to the DB and then in the end allow me to either commit or rollback them. If I insert an object, I should get it back in ...

How do I map to a parent or child in the same table with NHibernate?

Lets suppose that I have a Category table with a column that holds the id of a parent or child category from the same table. This design would allow me to have unlimited levels of Categories, or unlimited levels in a thread, for example. How can I map this relationship with NHibernate? Are there any disadvantages or warnings that I shou...

Need help with NHibernate / Fluent NHibernate mapping

Let's say your have the following table structure: ============================== | Case | ============================== | Id | int | | ReferralType | varchar(10) | +---------| ReferralId | int ...

NHibernate / Fluent - Mapping multiple objects to single lookup table

Hi all I am struggling a little in getting my mapping right. What I have is a single self joined table of look up values of certain types. Each lookup can have a parent, which can be of a different type. For simplicities sake lets take the Country and State example. So the lookup table would look like this: Lookups Id Key Valu...

How To Make NHibernate Automatically change an "Updated" column

I am applying NHibernate to an existing project, where tables and columns are already defined and fixed. The database is MS-SQL-2008. NHibernate 2.1.2 Many tables have a column of type timestamp named "ReplicationID", and also a column of type datetime named "UpdatedDT". I understand I might be able to use the <timestamp> element of t...

Serialized NHibernate Configuration objects - detect out of date or rebuild on demand?

I've been using serialized nhibernate configuration objects (also discussed here and here) to speed up my application startup from about 8s to 1s. I also use fluent-nhibernate, so the path is more like ClassMap class definitions in code fluentconfiguration xml nhibernate configuration configuration serialized to disk. The problem f...

unit test service layer - NUnit, NHibernate

Hi, I would like to unit test a DEPENDENT service layer which allows me to perform CRUD operation without mocking using NUnit. I know this is probably bad practice but I want to give it a try anyway - even if the tests have to run over night. My data is persisted using NHibernate and I have implemented a little library that 'bootstraps'...

TypeInitializationException When Getting an NHibernate Session

I’ve run into what appears to be an NHibernate config problem. Basically, I ran up a simple proof of concept persistence integration test using NUnit, the test simply queries an Oracle database and successfully returns the last record received by the underlying table. However, when the assemblies are taken out of the NUnit test environ...

NHibernate querying on any-associations meta-value

I have a collection of entities with an any-association, like this: public class CreatedLog { public string Message { get; set; } public EntityBase CreatedEntity { get; set; } // an association to any entity } Is there a way - through HQL or Criteria API - to find only the log entries, that are for a specific entity-type? Lik...

NHibernate 2nd lvl cache, custom query, sqldialect

I got trunk version of NH and FNH. When i try to add 2nd level cache, some parts of NHibernate forgets about chosen sqldialect. Initial configuration: var cfg = Fluently.Configure() .Database(MsSqlConfiguration.MsSql2008 .ConnectionString(connectionString) .DefaultSchema("dbo") .UseReflectionOptimizer() .Mappings(...

What is the fastest way to clear out a database using NHibernate?

I intend to perform some automated integration tests. This requires the db to be put back into a 'clean state'. Is this the fastest/best way to do this? var cfg = new Configuration(); cfg.Configure(); cfg.AddAssembly("Bla"); new SchemaExport(cfg).Execute(false, true, false); ...

How can I provide values for non-grouped columns in NHibernate?

I have a criteria query: Session.CreateCriteria<Sell043Report>() .SetProjection(.ProjectionList() .Add(LambdaProjection.GroupProperty<Sell043Report>(r => r.location)) .Add(LambdaProjection.GroupProperty<Sell043Report>(r => r.agent)) .Add(LambdaProjection.GroupProperty<Sell043Report>(r => r.cusip)) .Add(LambdaProjection...

NHibernate FetchMode.Lazy

I have an object which has a property on it that has then has collections which i would like to not load in a couple situations. 98% of the time i want those collections fetched but in the one instance i do not. Here is the code I have... Why does it not set the fetch mode on the properties collections? [DataContract(Name = "ThemingJ...

Unique Constraint Nhibernate.

I have a object with a Nhibernate mapping that has a surrogate ID and a natual ID. Since of cource the natural ID is uniquely constrained a insert query will fail if the object is already in the database with the same natural ID. My solution for this has been to manually check to see if natural IDs are in the database before trying to ...

How to dynamically modify NHibernate load queries at runtime? EventListeners? Interceptors?

I need to modify the query used to load many-to-one references in my model. It needs to work with lazily loaded entities as well. Specifically, I need to be able to further filter this data. Unfortunately, NH will not allow me to filter many-to-one relationships using the built in filtering system (?). I could just be doing something i...