【问题标题】:Problem using @SecondaryTable in Hibernate在 Hibernate 中使用 @SecondaryTable 的问题
【发布时间】:2009-04-02 14:40:08
【问题描述】:

我的架构的精简版:

utility_company
id int not null -- PK
name varchar(255) not null

utility_settings
utility_id -- FK to utility
use_magic tinyint(1) not null default 0

这两个表之间存在一对一的映射关系。撇开这种设计的适用性不谈,我想将这两个表中的数据映射到一个对象。在 Hibernate/JPA 中,据称这样做如下:

@Entity
@Table(name = "utility_company")
@SecondaryTables({
    @SecondaryTable(
        name = "utility_settings", 
        pkJoinColumns = {
            @PrimaryKeyJoinColumn(
                name="utility_id", referencedColumnName="id")
        })
})
public class UtilityCompany extends AbstractEntity {

等等。

每个@Column 都包含相应的表名。

当我部署时,我得到这个错误:

Cannot find the expected secondary table: 
no utility_company available for poscore.model.UtilityCompany

utility_company 表肯定存在(以前的版本仅将UtilityCompany 映射到utility_company 表;我正在添加utility_settings)。

发现许多论坛帖子都有这个确切的问题但没有答案。我还尝试了各种据称合法的形式来指定@SecondaryTable,所有这些都具有相同的效果。

有人成功使用@SecondaryTable,如果是,看到了吗?

【问题讨论】:

  • 我知道这个问题很老了,但是......我有同样的问题。你解决了吗?

标签: java hibernate jpa


【解决方案1】:

“每个@Column 都包含相应的表名。”

尝试删除第一个表名列的显式表名,只为辅助表列指定它。对我有用。

【讨论】:

    【解决方案2】:

    恕我直言,您的映射是正确的,并且使用 DataNucleus AccessPlatform 作为 JPA 实现运行良好。也许 Hibernates 日志会告诉你更多信息?

    --安迪DataNucleus

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-09-20
      • 2012-06-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-10-31
      • 1970-01-01
      相关资源
      最近更新 更多