【发布时间】: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 的首选方式!另一个问题是性能...我需要提高其他未在此处编写的方法的性能...
-
顺便说一句,我将使用与休眠无关的不同策略来解决我的问题...谢谢大家...