---
title: "hibernate annotation 定义字段的默认值和显示hql的格式化问题"
author: "fourfire"
date: "2008-06-19T10:54:15Z"
tags: []
slug: "hibernate-annotation-hql"
draft: false
lastmod: "2008-06-19T10:54:15Z"
id: 205673
url: "https://fourfire.iteye.com/blog/205673"
---

1 java类中定义属性的默认值并不能直接映射到数据库的定义当中
如 private String a="A";
public String getA(){};
数据库的a字段并没有default.
用annotations column中的columnDefinition可以解决
@Column(columnDefinition="varchar2(2) default '11'")
public String getA(){};
字段就可以存在默认值了
注意字段的类型必须指定，因为hibernate会把columnDefinition的内容直接写在生成标的ddl中，因此语法必须正确。
2 hql自动生成的sql很大，而且输出后不容易调试。

在框架中core-config.xml中的hibernateProperties段加入设定参数可以改变。

```xml

<prop key="hibernate.use_sql_comments">true</prop>//sql加注释
<prop key="hibernate.format_sql">true</prop>//sql格式化

```

输出结果见附件