Hibernate version: 1.2.0 beta 3
Hi,
I am trying to store a generic list but I do not know exactly what to do. I have the following structure:
Code:
internal class Person
{
string firstName = "Jane";
string lastName = "Doe";
int id;
internal Person(string fname, string lname)
{
this.firstname = fname;
this.lastname = lname;
}
internal int Id
{
get { return this.id; }
set { this.id = value; }
}
internal string FirstName
{
get { return this.firstName; }
set { this.firstName = value; }
}
internal string LastName
{
get { return this.lastName; }
set { this.lastName = value; }
}
}
internal class Broker
{
internal void GenerateAndStore()
{
List<Person> list = new List<Person>();
list.Add(new Person());
list.Add(new Person("John", "Smith"));
PersonDAO dao = new PersonDAO();
dao.Save(list);
}
}
internal class PersonDAO
{
internal void Save(List<Person> list)
{
//open session to database
ISession session = factory.OpenSession();
//store objects in database
session.SaveOrUpdateCopy(collection); [color=blue]<-- DOES NOT WORK[/color]
//close session
session.Close();
}
//this method works like a charme
internal List<Person> GetAllPersons()
{
//open session to database
ISession session = factory.OpenSession();
//get objects from database
List<Person> list = session.CreateCriteria(typeof (Person)).List<Person>();
//close session
session.Close();
}
}
Here the mapping file. What do I have to add for working with a generic list? I could not find any good thing in the documentation. The exampes there are all about collections.
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
<class name="MyNameSpace.Person, MyAssembly" table="persons">
<id name="Id" column="id" type="System.Int32">
<generator class="increment" />
</id>
<property name="FirstName" column="firstname" />
<property name="LastName" column="lastname" />
</class>
</hibernate-mapping>