【问题标题】:hibernate: How to map a variable as foreign keyhibernate:如何将变量映射为外键
【发布时间】:2012-08-31 21:26:15
【问题描述】:

是否可以将变量Long documentID 声明为外键而不是自然的Document document?下面的例子:

@Entity
@Table("document")
class Document{
   ...
   @Id
   Long id;
   ...
}

@Entity
@Table("something")
class Something{
   ....
   //instead of
   @ManyToOne
   Document document;

   // this one with the appropriate annotations
   Long documentID;
   ...
}

提前谢谢....

【问题讨论】:

  • 在 ORM 上使用的目的是将对象的逻辑表示转换为能够存储在数据库中的关系形式。如果你想直接处理外键,为什么要使用像 Hibernate 这样的 ORM?
  • 我想这样做,因为我不能修改 Document 类,所以我不能映射为双向映射,这是 Hibernate 的首选方式!另一个问题是性能...我需要提高其他未在此处编写的方法的性能...
  • 顺便说一句,我将使用与休眠无关的不同策略来解决我的问题...谢谢大家...

标签: java hibernate mapping


【解决方案1】:

好像已经出现了类似的问题:Hibernate. Foreign key mapping by id

不建议以这种方式使用hibernate。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-11-20
    • 1970-01-01
    • 1970-01-01
    • 2018-03-05
    • 2011-03-20
    • 1970-01-01
    • 2015-07-28
    • 1970-01-01
    相关资源
    最近更新 更多