Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp
Hibernate version: 1.0.3
Mapping documents: not relevant
Code between sessionFactory.openSession() and session.close():
Exception in a default constructor. Used to make sure the object is created with an alternative constructor (must use a parameter).
Debug level Hibernate log excerpt:
"Could not instantiate testobject<Name of Object that throws the exception>
The problem is that while calling "BuildSessionFactory()" all mapped objects will be test-instantiated and than always the default constructor is used.
In code, I can see that the default constructor throws an exception. This is because the programmer wants the object to only instantiate using the alternative constructor.
Like this:
Code:
Class Animal
{
private string name;
public Animal()
{ // default constructor is disallowed
throw Exception("Always give a name for the animal")
}
public Animal(string sName)
{
this.name = sName
}
This makes the BuildSessionFactory to throw the NHibernateException. "Could not instantiate testobjectAnimal"
How can I work around this and keep the Animal-class as it is?