【发布时间】:2018-02-09 11:01:10
【问题描述】:
我试图为 here 记录的多对多属性关系创建如下复合 PK:但当我使用 LongIdentity 时无法增强。现在的DataNucleus Enhancer不兼容吗?
@PersistenceCapable(identityType = IdentityType.APPLICATION, cacheable = "false", detachable = "true",
objectIdClass = CompanyProduct.PK.class)
public class CompanyProduct implements Serializable {
private static final long serialVersionUID = -7578808257727591074L;
@PrimaryKey
private Company company; // PK
@PrimaryKey
private Product product; // PK
...
public static class PK implements Serializable {
private static final long serialVersionUID = -2090216333556951760L;
public LongIdentity company; // Use same name as CompanyProduct field
public LongIdentity product; // Use same name as CompanyProduct field
public PK() {
}
public PK(String s) {
StringTokenizer st = new StringTokenizer(s, "::");
this.company = new LongIdentity(Company.class, st.nextToken());//
this.product = new LongIdentity(Product.class, st.nextToken());//
}
@Override
public String toString() {
return (company.toString() + "::" + product.toString());
}
...
Product.java
@PersistenceCapable(identityType = IdentityType.APPLICATION, cacheable = "false", detachable = "true")
public class Product implements Serializable {
private static final long serialVersionUID = 8269335445554701873L;
@PrimaryKey
@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
long id;
@Persistent(mappedBy = "product")
private Set<CompanyProduct> companyProducts = new HashSet<>();
...
公司.java
@PersistenceCapable(identityType = IdentityType.APPLICATION, cacheable = "false", detachable = "true")
public class Company implements Serializable {
private static final long serialVersionUID = 6364869685797117033L;
@PrimaryKey
@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
//private
long id;
@Persistent(mappedBy = "company")
private Set<CompanyProduct> companyProducts = new HashSet<>();
我做错了什么? datanucleus-maven-plugin 版本是 5.0.2,datanucleus-core 版本是 5.1.6。
【问题讨论】:
-
不管您的问题是什么,您为什么要引用不受支持的旧版本的文档? (无论如何你似乎都没有使用)
-
@Billy 感谢您指出这一点。当前的文档和版本在哪里?
-
好吧,当我想要他们的文档时,我会转到他们的主页并导航到我正在使用的版本;不知道为什么很难找到。 datanucleus.org:15080/products/accessplatform_5_1/jdo/…
-
我看过文档。对于像我这样的懒人,我必须像文档中那样为每个班级创建PK吗?有没有办法使用“SingleFieldIdentity”内置PK?因为如果我使用
public Company.PK company;这意味着我必须为它创建 PK 类而不是内置的 PK 类。 -
"SingleFieldIdentity" 不被 DataNucleus 使用,除此之外,您将代码绑定到一些内部 JDO 类。只要您永远不需要引用它,并且通过在您的类中对其进行硬编码,您就可以引用它,“内置”类就很好。显然,您可以贡献不需要的处理
标签: java jdo datanucleus