How to persist an enum using NHibernate

Why are you guys over complicating this? It is really simple. The mapping looks like this: <property name=”OrganizationType”></property> The model property looks like this: public virtual OrganizationTypes OrganizationType { get; set; } The Enum looks like this: public enum OrganizationTypes { NonProfit = 1, ForProfit = 2 } NHibernate will automatically figure it all out. … Read more

SaveOrUpdate Vs Update and Save in NHibernate

Chapter 9 covers all of this better than I can: http://nhibernate.info/doc/nh/en/index.html But cliff notes: Save() takes a new object without an identifier and attaches it to the session. The object will be INSERT‘d. Update() takes an existing object that has an identifier but is not in the session and attaches it to the session. The … Read more

How to delete child object in NHibernate?

You are getting the first error because, when you remove the items from the collection, NHibernate’s default mode of operation is to simply break the association. In the database, NHibernate tries to set the foreign key column on the child row to null. Since you do not allow nulls in that column, SQL Server raises … Read more

How do you map an enum as an int value with fluent NHibernate?

The way to define this convention changed sometimes ago, it’s now : public class EnumConvention : IUserTypeConvention { public void Accept(IAcceptanceCriteria<IPropertyInspector> criteria) { criteria.Expect(x => x.Property.PropertyType.IsEnum); } public void Apply(IPropertyInstance target) { target.CustomType(target.Property.PropertyType); } }

What’s the difference between session.Merge and session.SaveOrUpdate?

This is from section 10.7. Automatic state detection of the Hibernate Reference Documentation: saveOrUpdate() does the following: if the object is already persistent in this session, do nothing if another object associated with the session has the same identifier, throw an exception if the object has no identifier property, save() it if the object’s identifier … Read more

What is the difference between JoinQueryOver and JoinAlias?

Functionally they do the same thing, create a join to another entity. The only difference is what they return. JoinQueryOver returns a new QueryOver with the current entity being the entity joined, while JoinAlias returns the original QueryOver that has the current entity as the original root entity. Whichever one you use is a matter … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)