休眠列名问题 [英] hibernate column name issues

查看:23
本文介绍了休眠列名问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

@Column(name="DateOfBirth")
private Date dateOfBirth;

我特别需要上面的代码来创建一个名为DateOfBirth"的列,而 Hibernate 给了我一个名为 date_of_birth 的列.我怎样才能改变这个?有 web.xml 属性吗?我遇到过 DefaultNamingStrategy 和改进的NamingStrategy,但不确定如何指定其中之一.

I specifically need the above code to create a column named "DateOfBirth," instead Hibernate gives me a column named date_of_birth. How can I change this? Is there a web.xml property? I came across DefaultNamingStrategy and ImprovedNamingStrategy, but not sure how to specify one or the other.

推荐答案

这是一个可能的解决方法:如果您将其命名为 dateofbirth,则 DB 中的列将被命名为这样,但属性名称应该是一样的.

Here is a possible workaround: if you name it dateofbirth the column in the DB would be named like that, but the attribute name should be the same.

Hibernate 采用驼峰格式来创建/读取数据库列.

Hibernate takes the camel case format to create/read database columns.

我以前遇到过这个问题.我使用了旧列,其中列名称employeename"、employeerole"、departmentlocation"中没有空格.我讨厌它,因为我所有的 bean 属性都必须没有驼峰式外壳.

I've had this problem before. I worked with a legacy columns where there was no space in the column names "employeename", "employeerole", "departmentlocation". I hate it because all my beans properties had to be without camel case.

以_"分隔的数据库列将用于正确的驼峰命名,正如您刚刚看到的那样.

Database columns separated by "_" will be used to properly camelCase as you have just seen.

这篇关于休眠列名问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆