Exclusion of Hibernate configuration file exceptions

Source: Internet
Author: User
Tags numeric reflection throw exception

Recently in doing a small Web program, encountered a number of small problems, after the little brother's efforts have been resolved one after another, rejoice in the hope that these solutions choose one or two share with you. These problems are relatively elementary, master will not have to look, so as not to waste time, hehe.

Exception 1:*.hbm.xml element configuration exception in configuration file

Throw Exception Description:

Org.springframework.orm.hibernate3.HibernateSystemException:ids for this class must is manually assigned before calling Save (): Com.ebupt.ncsp.assist.service.department.domain.Department; Nested exception is org.hibernate.id.IdentifierGenerationException:ids to this class must be manually assigned Ling Save (): Com.ebupt.ncsp.assist.service.department.domain.Departmentorg.hibernate.id.IdentifierGenerationException:ids For this class must is manually assigned before calling Save (): Com.ebupt.ncsp.assist.service.department.domain.Department

Error or cause of exception:

The element is not configured correctly and the element is missing the configuration of its child elements.

Workaround:

The element maps the primary key field of the corresponding database table, and for its child elements, the value of class can be increment, identity, sequence, hilo, native ... And so on, more reference Hibernate reference documents, generally take the value of native.

In the configuration *. hbm.xml file I did not use the automatic generation tool, directly manually configured, which is also my carelessness, coupled with the hibernate reference is not very familiar, just according to gourd painting scoop, suggest everyone (novice) to see more reference documents, is very helpful.

Exception 2:*.hbm.xml element configuration exception in configuration file

Throw Exception Description:

Org.springframework.orm.hibernate3.HibernateSystemException:exception Setting property value with Cglib (set Hibernate.cglib.use-reflection-optimizer=false for more info) setter of Com.info.beran.com.SetComCode nested exception is Org.hibernate.PropertyAccessException:setting property value with Cglib (set Hibernate.cglib.use-reflection-optimizer=false for more info)

Error or cause of exception:

1. The types of fields in a database table (typically numeric fields) are inconsistent with the types configured in the configuration file.

2. In the database, the value of the numeric field is null.

The corresponding solution:

1. The type that modifies the type of the field in the configuration file to be the same is an integer.

2. Because null cannot be assigned to the original type, the field type (long, int, tinyint) of the numeric type in the metabase is mapped to an object type integer problem.

In fact, the above two exceptions are not encountered when mapping using the tool that automatically generates the configuration file, and I would like to cite these two examples to help you.

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.