Object Models in java and Relational Models in Databases

Source: Internet
Author: User

You also need to configure the object class to hibernate. cfg. xml, so that Hibernate can initialize the ing between the object class and the database table. If only the ing is configured, but not to hibernate. cfg. in xml, Hibernate still does not know which classes are Entity classes, because Hibernate cannot traverse all classes to determine which classes are Entity classes. A. if the object class is configured with @ annotation, you must use <mapping class = ""/> to configure the object class. In this way, their corresponding relationships have already been annotated with the object class, for example: @ Entity @ Table (name = "product_attribute") public class ProductAttribute {@ Id @ GeneratedValue (strategy = GenerationType. AUTO) private Integer id; @ ManyToOne (cascade = CascadeType. MERGE) @ JoinColumn (name = "productId") private ProductInfoEntity productInfo; @ ManyToOne (cascade = CascadeType. MERGE) @ JoinColumn (name = "pro_attr_m EtaId ") private ProductAttributeMetaEntity productAttributeMeta; @ Column (name =" value ") private String value; B. if the XML file is used for configuration, you must use <mapping resource = ""/> to configure the XML configuration file. For example, each object model (entity) should have its own configuration file named "entity name. hbm. xml, and finally the object name. hbm. xml is introduced to hibernate. cfg. c. code hibernate. cfg. xml # declare the object class configured with @ annotation in Hibernate <mapping class = "com. helloweenvsfei. hibernate. bean. department "/> <mapping class =" com. helloweenvsfei. hibernate. bean. employee "/> # declare the object class configured with XML in Hibernate <mapping resource =" com/helloweenvsfei/hibernate/bean/Event. hbm. xml "/> <mapping resource =" com/helloweenvsfei/hibernate/bean/Cat. hbm. xml "/>

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.