POJO class and ing configuration file, pojo ing configuration file

Source: Internet
Author: User

POJO class and ing configuration file, pojo ing configuration file

Requirements on persistent objects

1. Provides a no-argument Constructor so that Hibernate can use Constructor. newInstace () to instantiate a persistent object.

2. Provide an identifier property ). It is usually mapped to the primary key field of the database table. Without this attribute, some functions will not work, such as Session. saveOrUpdate ().

3. Declare the access method (set/get) for fields of the persistence class ). Hibernate implements persistence for javaBean-style attributes.

4. Using a non-final class, generating a proxy at runtime is an important function of Hibernate. If the persistence class does not implement any interfaces, Hibernate uses CGLB to generate a proxy. If the final class is used, the CGLIB proxy cannot be generated.

5. Rewrite the equals () and hashCode () methods. If you need to put the persistence class in the Set (when you need to perform Association ing), you should rewrite these two methods.

For non-primary key elements in the ing configuration file, use the <property> tag ing. The <property> tag type attribute is used to specify the persistence class and the type in the data table.

You can write the full name of the class in Java or the Hibernate type.

Ing primary key attributes

We recommend that you use the corresponding packaging type if the primary key is a number.

The id element is used to map the primary key. The class attribute of the child element <generator> of the id element is used to specify the primary key generation policy.

The common values are as follows:

Identity: use the automatic growth policy of the database. Not all databases support this policy. For example, Oracle does not support this policy.

Sequence: Uses sequence in DB2, PostgreSQL, Oracle, and SAPDB.

Hilo: uses a high-status algorithm to generate a primary key. Only one additional table is required. All databases support this function.

Increment: maintained by Hibernate. It first queries the current largest id value, and increases by 1. It is not recommended because of thread security issues.

Assigned: Specifies the primary key manually.

 


Can myeclipse generate a ing file and a database table by using the pojo class?

MYeclipse does not have this function, but it is special?
Pojo directly generates the configuration file to the table and does not know how to create the table name.

We know that hibernate has a tool that can generate a pojo configuration file and a schema for the database. It can generate a configuration file from the schema. I have not heard of any conversion from POJO.

In myeclipse, how does one generate a POJO Class Based on * hbmxml files?

Generate a configuration file based on the table, modify the configuration file based on business needs, and then generate pojo Based on the configuration file

Related Article

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.