Hi!
I've got two business entities: Project and User. There is
many-to-many association between them:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
auto-import="true" assembly="DAL" namespace="DAL.DataEntities">
<class name="ProjectEntity" table="projects" lazy="false">
<id name="ID" column="id">
<generator class="native" />
</id>
<property name="Name" column="name" not-null="true"/>
<property name="Description" column="description"/>
<property name="CreateDate" column="create_date" not-null="true"/>
<property name="StartDate" column="start_date"/>
<property name="DueDate" column="due_date"/>
</class>
</hibernate-mapping>
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
auto-import="true" assembly="DAL" namespace="DAL.DataEntities">
<class name="UserWithProjectsEntity" table="users" lazy="false"
polymorphism="explicit">
<id name="ID" column="id">
<generator class="native" />
</id>
<property name="UserName" column="user_name" not-null="true"/>
<property name="Password" column="password" not-null="true"/>
<property name="Email" column="email" not-null="true"/>
<property name="IsActive" column="is_active" type="boolean"
not-null="true"/>
<property name="IsActivated" column="is_activated" type="boolean"
not-null="true"/>
<property name="RegistrationDate" column="registration_date"
not-null="true"/>
<bag name="Projects" table="users_projects" lazy="true" cascade="all">
<key column="user_id"/>
<many-to-many column="project_id"
class="DAL.DataEntities.ProjectEntity, NHibernateManyToMany"/>
</bag>
</class>
</hibernate-mapping>
When I change projects collection inside some user NHibernate
generates several queries:
NHibernate: UPDATE users SET user_name = :p0, password = :p1, email = :p2, is_ac
tive = :p3, is_activated = :p4, registration_date = :p5 WHERE id = :p6;:p0 = 'jd
oe' [Type: String (0)], :p1 = 'SBNJTRN+FjG7owHVrKtue7eqdM4RhdRWVl71HXN2d7I=' [Ty
pe: String (0)], :p2 = '[email protected]' [Type: String (0)], :p3 = True [Ty
pe: Boolean (0)], :p4 = True [Type: Boolean (0)], :p5 = 23.10.2011 10:09:33 [Typ
e: DateTime (0)], :p6 = 42 [Type: Int32 (0)]
NHibernate: UPDATE projects SET name = :p0, description = :p1, create_date = :p2
, start_date = :p3, due_date = :p4 WHERE id = :p5;:p0 = 'Project1' [Type: String
(0)], :p1 = 'Edited3' [Type: String (0)], :p2 = 28.10.2011 11:24:24 [Type: Date
Time (0)], :p3 = 30.10.2011 15:24:24 [Type: DateTime (0)], :p4 = 28.10.2012 15:2
4:24 [Type: DateTime (0)], :p5 = 8 [Type: Int32 (0)]
NHibernate: UPDATE projects SET name = :p0, description = :p1, create_date = :p2
, start_date = :p3, due_date = :p4 WHERE id = :p5;:p0 = 'Project2' [Type: String
(0)], :p1 = 'test' [Type: String (0)], :p2 = 31.10.2011 1:00:00 [Type: DateTime
(0)], :p3 = 01.11.2011 1:00:00 [Type: DateTime (0)], :p4 = 12.11.2011 1:00:00 [
Type: DateTime (0)], :p5 = 10 [Type: Int32 (0)]
NHibernate: DELETE FROM users_projects WHERE user_id = :p0;:p0 = 42 [Type: Int32
(0)]
NHibernate: INSERT INTO users_projects (user_id, project_id) VALUES (:p0, :p1);:
p0 = 42 [Type: Int32 (0)], :p1 = 8 [Type: Int32 (0)]
NHibernate: INSERT INTO users_projects (user_id, project_id) VALUES (:p0, :p1);:
p0 = 42 [Type: Int32 (0)], :p1 = 10 [Type: Int32 (0)]
Is it possible to turn off update queries for entities but still have
the ability to manage associations in automatical mode? (e.g. update
only associations but not entity attributes).
Thanks!
--
You received this message because you are subscribed to the Google Groups
"nhusers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/nhusers?hl=en.