Hello together,
i'm facing a strange problem with a class containing a composite key.
Here is my code:
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
<class name="PBC.Lock,PBC" table="locks" lazy="false">
<composite-id access="property">
<key-property column="object_id" name="Id"/>
<key-property column="object_type" name="ObjectType"/>
</composite-id>
<property column="object_id" name="Id" type="Int64" not-null="true" />
<property column="object_type" type="String" name="ObjectType" not-null="true"/>
<property column="client_id" name="ClientId" not-null="true"/>
</class>
</hibernate-mapping>
Code:
[Serializable]
public class Lock
{
private long _id;
private string _objectType;
private long _clientId;
public Lock(long id, Type objType, long clientId)
{
_id = id;
_objectType = objType.Name;
_clientId = clientId;
}
public Lock()
{
}
#region Properties
public long Id
{
get { return _id; }
set { _id = value; }
}
public string ObjectType
{
get { return _objectType; }
set { _objectType = value; }
}
public long ClientId
{
get { return _clientId; }
set { _clientId = value; }
}
#endregion
#region Equals And HashCode Overrides
public override bool Equals(object obj)
{
if (this == obj) return true;
if ((obj == null) || (obj.GetType() != this.GetType())) return false;
Lock castObj = (Lock)obj;
return (castObj != null) &&
(this._id == castObj.Id
&& this._objectType == castObj._objectType
);
}
public override int GetHashCode()
{
int hash = 57;
hash = 27 * hash * (_id.GetHashCode() + _objectType.GetHashCode());
return hash;
}
#endregion
}
When i try to save a Lock Object i get the following Error:
2008-05-13 11:41:09,987 INFO / Class: NHibernate.Loader.Loader L: 0 / GetResultSet (..) -> SELECT lock0_.object_id as object1_12_0_, lock0_.object_type as object2_12_0_, lock0_.client_id as client3_12_0_ FROM locks lock0_ WHERE lock0_.object_id=:p0 and lock0_.object_type=:p1 / File:
2008-05-13 11:41:11,915 WARN / Class: NHibernate.Util.ADOExceptionReporter L: 0 / LogExceptions (..) -> Npgsql.NpgsqlException:
column "object_id" specified more than once
Severity: ERROR
Code: 42701
at Npgsql.NpgsqlConnector.CheckErrors()
at Npgsql.NpgsqlConnector.CheckErrorsAndNotifications()
at Npgsql.NpgsqlCommand.ExecuteCommand()
at Npgsql.NpgsqlCommand.ExecuteNonQuery()
at NHibernate.Impl.BatcherImpl.ExecuteNonQuery(IDbCommand cmd)
at NHibernate.Impl.NonBatchingBatcher.AddToBatch(IExpectation expectation)
at NHibernate.Persister.Entity.AbstractEntityPersister.Insert(Object id, Object[] fields, Boolean[] notNull, Int32 j, SqlCommandInfo sql, Object obj, ISessionImplementor session) / File:
2008-05-13 11:41:11,919 ERROR / Class: NHibernate.Util.ADOExceptionReporter L: 0 / LogExceptions (..) -> ERROR: 42701: column "object_id" specified more than once / File:
2008-05-13 11:41:11,923 ERROR / Class: NHibernate.Impl.SessionImpl L: 0 / Execute (..) -> could not synchronize database state with session / File:
NHibernate.ADOException: could not insert: [PBC.Lock#PBC.Lock][SQL: INSERT INTO locks (object_id, object_type, client_id, object_id, object_type) VALUES (?, ?, ?, ?, ?)] ---> Npgsql.NpgsqlException:
column "object_id" specified more than once
Severity: ERROR
Code: 42701
at Npgsql.NpgsqlConnector.CheckErrors()
at Npgsql.NpgsqlConnector.CheckErrorsAndNotifications()
at Npgsql.NpgsqlCommand.ExecuteCommand()
at Npgsql.NpgsqlCommand.ExecuteNonQuery()
at NHibernate.Impl.BatcherImpl.ExecuteNonQuery(IDbCommand cmd)
at NHibernate.Impl.NonBatchingBatcher.AddToBatch(IExpectation expectation)
at NHibernate.Persister.Entity.AbstractEntityPersister.Insert(Object id, Object[] fields, Boolean[] notNull, Int32 j, SqlCommandInfo sql, Object obj, ISessionImplementor session)
--- End of inner exception stack trace ---
at NHibernate.Persister.Entity.AbstractEntityPersister.Insert(Object id, Object[] fields, Boolean[] notNull, Int32 j, SqlCommandInfo sql, Object obj, ISessionImplementor session)
at NHibernate.Persister.Entity.AbstractEntityPersister.Insert(Object id, Object[] fields, Object obj, ISessionImplementor session)
at NHibernate.Impl.ScheduledInsertion.Execute()
at NHibernate.Impl.SessionImpl.Execute(IExecutable executable)
at NHibernate.Impl.SessionImpl.ExecuteAll(IList list)
at NHibernate.Impl.SessionImpl.Execute()
Does anyone know what's responsible for this message?
Regards