【发布时间】:2010-11-22 03:27:58
【问题描述】:
我的应用程序类使用了一个库,其中默认包含两个变量。
// A class from framework:
public class SuperClass implements Serializable {
private long id;
private long version;
// getter and setter methods for these variables...
}
我应该扩展这个类,以便访问框架的一些功能。
如果我像这样将这个类扩展到我自己的类:
public class MyClassChild extends SuperClass {
private long myprimarykey;
private String some column;
private long myversion;
// getter and setter methods for these variables...
}
根据编程模型,这两个变量也可以访问。
在实现需要 SuperClass 类型的 Object 的操作时。
有什么想法可以扩展不包括这两个变量 (id, version) 的 SuperClass 吗?
我不知道该怎么办?
有什么建议吗?
谢谢
【问题讨论】:
-
这些变量如何在您的子类中可见?它们被声明为私有的,而不是受保护的。
-
我猜你是在使用像 Hibernate 或 JPA 这样的 ORM 框架?您可以看到这些变量的唯一方法是通过反射。只是您不希望这些变量保留在您的子类中吗?
-
正是男人。如何不持久化这两个变量?
-
你在使用 JPA 注释吗?
-
是的,使用 Eclipselink [eclipse.org/eclipselink/jpa.php].
标签: java jpa eclipselink