Hibernate basic knowledge Finishing (vi)

Source: Internet
Author: User

Listening in Hibernate

The event monitoring mechanism in hibernate can listen to the action of the session object, and hibernate invokes the event-handling method in the listener class once a special event occurs. In some features of the design, can either use Hibernate interceptor implementation, or can use Hibernate's event monitoring to achieve.

Hibernate can also be used to monitor, perform before and after the save operation.
The first step:
Write listeners to implement specific interfaces. Different interfaces are implemented for different operations.

Step Two: Configure the Listener

Concrete operation according to the actual implementation.
Best Practices for Hibernate
1, more use of fine-grained components, componment
2, the primary key is best meaningless
3, preferably each persistent class corresponds to a mapping file
4, consider putting the query string outside the program, that is, using a named query
5. Using Bound variables: =name
6, do not treat anomalies as recoverable, try to use runtimeexception instead of exception
7. Consider abstracting hibernate code from business logic code
8, multi-use bidirectional association



Hibernate basic knowledge Finishing (vi)

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.