D
D
Dem0n132014-12-30 12:45:04
NHibernate
Dem0n13, 2014-12-30 12:45:04

NHibernate: how to determine equality of transient and persistent objects?

There are classes inherited from

public abstract class DomainObject
{
        public int Id { get; private set; } // суррогатный id для базы
}

Objects of these classes come over the network and are stored in the database, thereby getting an Id and becoming persistent.
The problem is that objects can come the same in terms of business keys, but different in terms of hibernate (one of them may already be in the database and have an id, and the second one has just arrived over the network).
How can I determine in the simplest way whether the database contains the same object in terms of business keys?
In what direction dug:
1. Use composite-id from business keys. Then you have to remove the surrogate Id and it seems like there may be problems when joining, but the database search works and I can determine that the same object is already in the database.
2. Use natural-id from business keys in addition to surrogate id. It didn't work, the search by only works by the id field (maybe nhibernate can search by natural-id?)
3. Use the unique-key attribute, which I put on all business keys. It gave nothing, except for Exception when trying to insert the same object, but I can’t check it.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question