Hibernate忽略扩展类的@Table(name =" ...") - 创建的表名都是小写的 [英] Hibernate ignores @Table(name = "...") for extended classes - created tablenames are all lower case

查看:295
本文介绍了Hibernate忽略扩展类的@Table(name =" ...") - 创建的表名都是小写的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们通过Hibernate自动创建表格:

  @Table(name =some_table)

曾用于普通实体。但是当我们有一个抽象基类时:

$ p $ @Entity
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
public class PersonBankAccount extends AbstractPersistable< Long> {b $ b



<$ p $ @Entity
@Table(name =person_bank_account)
public class PersonBankAccountSimple extends PersonBankAccount {

数据库中的结果表被命名为

  personbankaccount 

这是怎么回事?

autogenerator说: / p>

 找不到表格:PersonBankAccount 

当第一次创建它并重新运行时他说:

 找到的表:personbankaccount 

正如我所说的,对于普通表,一切正常。

解决方案

不应该是基类中表的名字。

  @Entity 
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@Table(name =person_bank_account)
public class PersonBankAccount e xtends AbstractPersistable< Long> {


We create our tables automaticly via Hibernate by assigning:

@Table(name = "some_table") 

That used to work for "normal" entities. But when we have an abstract base class:

@Entity
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
public class PersonBankAccount extends AbstractPersistable<Long> {

that is extended by

@Entity
@Table(name = "person_bank_account")
public class PersonBankAccountSimple extends PersonBankAccount {

The resulting table in the database is named

personbankaccount

What is going on here?

The autogenerator says:

table not found: PersonBankAccount 

when first creating it and on rerun he says:

table found: personbankaccount

Like I said, for normal tables everything works fine.

解决方案

Shouldn't be the name of table in the base class instead.

@Entity
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@Table(name = "person_bank_account")
public class PersonBankAccount extends AbstractPersistable<Long> {

这篇关于Hibernate忽略扩展类的@Table(name =&quot; ...&quot;) - 创建的表名都是小写的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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