Category: NHibernate
-
Implementing Equals() and GetHashCode() in ORM classes with autoincrement keys
The requirements for implementing Equals() and GetHashCode() in .Net are very hard to satisfy and in some areas nearly impossible. There are some situations where an object’s identity inevitably changes, and saving an ORM-mapped object with autogenerated key is a case in point. Making its hash code conform with requirements would require an inordinately large…
-
Workaround for HQL SELECT TOP 1 in a subquery
HQL doesn’t seem to support clauses like “SELECT TOP N…”, which can cause headaches when for example you need to get the data for the newest record from a table. One way to resolve this would be to do something like “SELECT * FROM X WHERE ID in (SELECT ID FROM X WHERE Date IN…
-
Repository moved temporarily to ‘/viewvc/nhibernate/trunk/’; please relocate
When trying to switch my local Subversion copy of the NHibernate source to a different tag (from 3.1GA to trunk, in this case), I got this error: Repository moved temporarily to ‘/viewvc/nhibernate/trunk/’; please relocate The frustrating thing was that I was trying to relocate to exactly this url. And if I tried others, it said…
-
How to make LINQ to NHibernate eager-load joined properties like the Criteria API
In terms of “lazyness” of a property, there are currently three different ways in which it can be mapped in NHibernate: lazy=”false” means that it’s not lazy at all – the property’s content will be loaded along with its owner object. This means additional data is always loaded when you load an object, and may…
-
Collection owner not associated with session? Not quite.
I hate when this happens. I upgraded to NHibernate 2.0 and then quickly afterward to 2.1.0 (you guessed it: because of LINQ). I had to change a couple of things to support it in my company’s application framework and it all seemed to work well – until I discovered that deleting any entity that has…
-
NHibernate 2.1 updates schema metadata without being asked to
In NHibernate 2.1, the session factory is set up to access the database immediately when you build it. This is done by a Hbm2ddl component to update something called SchemaMetaData: I’m not sure what this is all about, but I am certain that such behaviour is not nice. The previous version of NHibernate didn’t do…
-
NHibernate queued adds on lazy-load collections
I don’t know if this behaviour is documented (well, yeah, the (N)Hibernate documentation is pretty thin but it’s improving), I wasn’t fully aware of it and this caused a bug… I’m posting this in hope it may save for someone else the time I have lost today :). In our software we use a custom…
-
Supporting triggers that occasionally generate values with NHibernate
NHibernate supports fields that are generated by the database, but in a limited way. You can mark a field as generated on insert, on update, or both. In this case, NHibernate doesn’t write the field’s value to the database, but creates a select statement that retrieves its value after update or insert. Ok, but what…