没有成员的列 [英] Column without member
问题描述
使用Hibernate,我们试图使它为抽象类创建一个附加列-但是我们不能向该类添加新成员(大规模消耗内存).我们需要让Hibernate创建模式(开发阶段hibernate.hbm2ddl.auto=update
).
Using Hibernate we're trying to have it create an additional column to an abstract class - but we can't add a new member to this class (memory consumption in large scale). We need to have Hibernate create the schema (development phase, hibernate.hbm2ddl.auto=update
).
假设我们有一个 MyClass 实体类,成员为 a,b,c ,我们希望Hibernate也创建一个列 d .该列在内存中不需要,仅在 MyClass 实例的保存/加载期间通过HQL/SQL进行访问.
Let's say we have a MyClass entity class with members a,b,c, and we would like Hibernate to also create a column d. This column is not needed in memory and will be accessed only via HQL/SQL during saving/loading times of MyClass instances.
可以做到吗?
注意:
1. Hibernate 3.6.0 Final + Oracle 11g +纯Java
2.我们使用注释,没有xml文件
Notes:
1. Hibernate 3.6.0 Final + Oracle 11g + pure Java
2. We use annotations, no xml files
推荐答案
将属性添加到类中,但使其变得懒惰(使用@Basic(fetch = FetchType.LAZY)
批注).
Add the property to the class, but make it lazy (using the @Basic(fetch = FetchType.LAZY)
annotation).
确保在构建时对类进行了检测:这是工作所需的.有关更多详细信息,请参见本章文档.
Make sure your classes are instrumented at build time: it's needed for this to work. More details are available in this chapter of the documentation.
这篇关于没有成员的列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!