在Hibernate映射文件中使用方括号作为列属性

时间:2013-01-17 20:50:00

标签: xml hibernate

hibernate映射文件中的列名周围的[]是什么意思吗?

实施例

<property name="tableCol" column="[TABLE_col]" not-null="false" type="long" unique="false" optimistic-lock="true" lazy="false" generated="never" /> 

VS

<property name="tableCol" column="TABLE_col" not-null="false" type="long" unique="false" optimistic-lock="true" lazy="false" generated="never" />  

1 个答案:

答案 0 :(得分:0)

如果要将数据库保留关键字用作列名,则使用列名称周围的[]

示例:

如果您有一个名为DESC的列是数据库保留关键字,如果您尝试使用它将导致JDBCException

<property name="tableCol" type="string" >
    <column name="DESC" type="long" not-null="false" />
</property>

您必须使用:

<property name="tableCol" type="string" >
    <column name="[DESC]" type="long" not-null="false" />
</property>