---
title: "Hibernate 字段配置关系"
author: "ljl.java"
date: "2013-01-23T21:47:44Z"
tags: []
categories: ["企业架构"]
slug: "hibernate"
draft: false
lastmod: "2013-01-24T10:15:23Z"
id: 1774730
url: "https://ljl-java.iteye.com/blog/1774730"
---

根据业务需求在两张表中加了两个字段

做个总结：

column为实体中的字段名称 (基础表的字段)

name为自己指定的虚拟名称

Llt\_Org\_Info表中show\_category字段与llt\_system\_code表中code字段配置关联关系

之前配置

&lt;many-to-one name=" show\_category " column="type" class="System\_code" not-null="true"/&gt;

错误1：column应为实体中的字段名称 (本想直接关联上llt\_system\_code表的type字段,测试后配置错误)

Llt\_Org\_Info 基础表中xml中增加配置

&lt;property name="show\_category" column="show\_category" type="string" not-null="false" length="500" /&gt;

 

&lt;property name="recommend\_flag" column="recommend\_flag" type="string" not-null="false" length="1"/&gt;

llt\_system\_code表中xml 配置

&lt;id name="id" type="integer" column="id"&gt;&lt;generator class="sequence"&gt;&lt;param name="sequence"&gt;SEQ\_LLT\_SYSTEM\_CODE&lt;/param&gt;&lt;/generator&gt;&lt;/id&gt;

&lt;property name="name" column="name" type="string" not-null="true" length="100"/&gt;

&lt;property name="code" column="code" type="string" not-null="true" length="10"/&gt;

&lt;property name="type" column="type" type="string" not-null="true" length="2"/&gt;

 

hibernate中只需指定字段的基本信息hql查询时，就会根据表的id自带关联上其他属性将其引出