简体   繁体   English

DataNucleus Enhancer在LongIdentity上失败。 (datanucleus-maven-plugin 5.0.2)

[英]DataNucleus Enhancer fails on LongIdentity. (datanucleus-maven-plugin 5.0.2)

I was trying to create composite PK as follows for many-to-many-attributed relationship as documented here : but could not enhance when I use LongIdentity . 我试图创建复合PK作为作为记录了许多一对多归于关系如下位置 :但是当我使用未明显增强LongIdentity Is the current DataNucleus Enhancer not compatible with it? 当前的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 产品.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<>();
  ...

Company.java 公司.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<>();

What am I doing wrong? 我究竟做错了什么? datanucleus-maven-plugin version is 5.0.2 and datanucleus-core version is 5.1.6. datanucleus-maven-plugin版本是5.0.2, datanucleus-core版本是5.1.6。

Based on the discussion and my trial on this case of deciding on which identity to use, I found it convenient to continue with the Application identity by adding a single field to the intermediate class to be its Application identity (generated value). 基于讨论和对决定使用哪种身份的案例的试验,我发现通过在中间类中添加一个字段作为其Application identity (生成的值),可以方便地继续Application identity With these I don't need to write the PK Class manually. 有了这些,我不需要手动编写PK类。 Hence, I have my code as follows; 因此,我的代码如下:

CompanyProduct.java (many_to_many_attributed) CompanyProduct.java(many_to_many_attributed)

@PersistenceCapable(identityType = IdentityType.APPLICATION, cacheable = "false", detachable = "true")
public class CompanyProduct implements Serializable {

private static final long serialVersionUID = -7578808257727591074L;

@PrimaryKey
@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
long id;
@Persistent
private Company company;
@Persistent
private Product product; 

...

Company.java 公司.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)
long id;
@Persistent(mappedBy = "company")
private Set<CompanyProduct> companyProducts = new HashSet<>();

...

Product.java 产品.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<>();
...

This is what I have settled for now unless one advised me against the use of "Application identity". 除非有人建议我不要使用“应用程序身份”,否则这就是我现在已经解决的问题。 Thanks to @Billy and @DN1 感谢@Billy和@ DN1

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM