NHibernate entity class primary Key ID assignment problem

Source: Internet
Author: User

A colleague suddenly came to me, said he encountered a problem, in the call NHibernate update data when the error, said there is data row lock.

Look at the code, no problem.

It is not a problem to insert the database directly in the Pl/sql developer. There should be no transaction not committed, the table is locked. But we are low level, to prevent in case, or restart the database. After a hard reboot, try again, the problem is still, several times sunset red.

I later changed the update to insert and found that it was still wrong. Find the details of the error, prompting you to use a sequence called "seq_hibernate" (remember not very clearly). We have not defined this sequence, is this a sequence of nhibernate bands.

Look for it, find the entity class code here, the primary key ID does not define how to assign a value.

Generally, in NHibernate, entity class mappings, there are two ways to assign a value to an ID

Id (S => s.id). Generatedby.assigned (); Directly assigned value
Id (S => s.id). Generatedby.sequence ("Seq_website"); Using sequence

But that's what my colleague wrote:

Id (S => s.id);

There is no way to specify. Guessing is because the primary key ID is not assigned the assignment method, NHibernate the default method, using the default sequence Seq_hibernate (?) To produce a value for it. God knows that this seq_hibernate may be a lot of places in the request, so they reported a lock error.

The problem is resolved after the sequence is specified using the ID in a similar way.

Id (S => s.id). Generatedby.sequence ("Seq_website"); Using sequence

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.