0

複合キーを使用して追加のテーブルを介してエンティティをバインドする際に問題があります。

クラス製品

@Entity
public class Product implements Serializable {
    @Id
    @Column(name = "product_id")
    private Integer productId;
    ...
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "product", fetch = FetchType.LAZY)
    private Collection<ProductProperty> productPropertyCollection;
    ...
    get/set
    ...
    public void addProductProperty(ProductProperty productProperty) {
        productPropertyCollection.add(productProperty);
        if (productProperty.getProduct()!=this) {
            productProperty.setProduct(this);
        }
    }
}

クラス プロパティ

@Entity
public class Property implements Serializable {
    @Id
    @Column(name = "property_id")
    private Integer id;
    ...
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "property", fetch = FetchType.LAZY)
    private Collection<ProductProperty> productPropertyCollection;
    ...
    get/set
    ...
    public void addProductProperty(ProductProperty productProperty) {
        productPropertyCollection.add(productProperty);
        if (productProperty.getProperty()!=this) {
            productProperty.setProperty(this);
        }
    }

}

クラス ProductProperty

@Entity
@IdClass(ProductPropertyPK.class)
public class ProductProperty implements Serializable {

    @Id
    @ManyToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
    @JoinColumn(name = "property_id", referencedColumnName = "property_id")
    private Property property;

    @Id
    @ManyToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
    @JoinColumn(name = "product_id", referencedColumnName = "product_id")
    private Product product;

    public void setProperty(Property property) {
        this.property = property;
        if (!property.getProductPropertyCollection().contains(this)) {
            property.getProductPropertyCollection().add(this);
        }
    }

    public void setProduct(Product product) {
        this.product = product;
        if (!product.getProductPropertyCollection().contains(this)) {
            product.getProductPropertyCollection().add(this);
        }
    }

}

エンティティの使用:

for (Offer o : offers.getOffers()) {
    jpa.product.Product product = cacheProduct_indexIdx.get(o.getProductsId());   
    for (Property p : o.getProperties()) {                   
        PropertyTypeNamePK propertyTypeNamePK = new PropertyTypeNamePK(p.getType(), p.getName());
        if (!cacheProperty_indexTypeNamePK.containsKey(propertyTypeNamePK)) {
            jpa.product.Property property = new jpa.product.Property();
            property.setType(p.getType());
            property.setName(p.getName());
            propertyFacade.create(property);

            jpa.product.ProductProperty productProperty = new ProductProperty();
            product.addProductProperty(productProperty);
            property.addProductProperty(productProperty);

            cacheProperty_indexTypeNamePK.put(propertyTypeNamePK, property);    
        } else {
            jpa.product.Property property = cacheProperty_indexTypeNamePK.get(propertyTypeNamePK);

            jpa.product.ProductProperty productProperty = null;
            for (jpa.product.ProductProperty pp : product.getProductPropertyCollection()) {
                if (property.equals(pp.getProperty())) {
                    productProperty = pp;
                    break;
                }
            }
            if (productProperty==null) {
                productProperty = new ProductProperty();
                product.addProductProperty(productProperty);
                property.addProductProperty(productProperty);
            }
        }
    }
}

1, 10, 100 では問題なく動作しますが、1000 以上ではエラーがスローproductsされるため、どこかにエラーがあります。products

Caused by: java.lang.StackOverflowError
    at java.text.DecimalFormat.subformat(DecimalFormat.java:903)
    at java.text.DecimalFormat.format(DecimalFormat.java:692)
    at java.text.DecimalFormat.format(DecimalFormat.java:626)
    at java.text.SimpleDateFormat.zeroPaddingNumber(SimpleDateFormat.java:1335)
    at java.text.SimpleDateFormat.subFormat(SimpleDateFormat.java:1274)
    at java.text.SimpleDateFormat.format(SimpleDateFormat.java:978)
    at java.text.SimpleDateFormat.format(SimpleDateFormat.java:948)
    at java.text.DateFormat.format(DateFormat.java:336)
    at com.sun.enterprise.server.logging.UniformLogFormatter.uniformLogFormat(UniformLogFormatter.java:265)
    at com.sun.enterprise.server.logging.UniformLogFormatter.format(UniformLogFormatter.java:162)

    at java.util.logging.StreamHandler.publish(StreamHandler.java:196)
    at java.util.logging.ConsoleHandler.publish(ConsoleHandler.java:105)
    at java.util.logging.Logger.log(Logger.java:565)
    at org.eclipse.persistence.logging.JavaLog.internalLog(JavaLog.java:290)
    at org.eclipse.persistence.logging.JavaLog.log(JavaLog.java:261)
    at org.eclipse.persistence.internal.sessions.AbstractSession.log(AbstractSession.java:3215)
    at org.eclipse.persistence.internal.sessions.AbstractSession.log(AbstractSession.java:4333)
    at org.eclipse.persistence.internal.sessions.AbstractSession.log(AbstractSession.java:4305)
    at org.eclipse.persistence.internal.sessions.AbstractSession.log(AbstractSession.java:4281)
    at org.eclipse.persistence.internal.sessions.AbstractSession.log(AbstractSession.java:4203)
    at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.logDebugMessage(UnitOfWorkImpl.java:5559)
    at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.registerNotRegisteredNewObjectForPersist(UnitOfWorkImpl.java:4250)
    at org.eclipse.persistence.internal.sessions.RepeatableWriteUnitOfWork.registerNotRegisteredNewObjectForPersist(RepeatableWriteUnitOfWork.java:511)
    at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.discoverAndPersistUnregisteredNewObjects(UnitOfWorkImpl.java:4160)
    at org.eclipse.persistence.mappings.CollectionMapping.cascadeDiscoverAndPersistUnregisteredNewObjects(CollectionMapping.java:426)
    at org.eclipse.persistence.internal.descriptors.ObjectBuilder.cascadeDiscoverAndPersistUnregisteredNewObjects(ObjectBuilder.java:1964)
    at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.discoverAndPersistUnregisteredNewObjects(UnitOfWorkImpl.java:4178)
    at org.eclipse.persistence.mappings.ObjectReferenceMapping.cascadeDiscoverAndPersistUnregisteredNewObjects(ObjectReferenceMapping.java:938)
    at org.eclipse.persistence.mappings.ObjectReferenceMapping.cascadeDiscoverAndPersistUnregisteredNewObjects(ObjectReferenceMapping.java:916)
    at org.eclipse.persistence.internal.descriptors.ObjectBuilder.cascadeDiscoverAndPersistUnregisteredNewObjects(ObjectBuilder.java:1964)
    at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.discoverAndPersistUnregisteredNewObjects(UnitOfWorkImpl.java:4178)
    at org.eclipse.persistence.mappings.CollectionMapping.cascadeDiscoverAndPersistUnregisteredNewObjects(CollectionMapping.java:426)
    at org.eclipse.persistence.internal.descriptors.ObjectBuilder.cascadeDiscoverAndPersistUnregisteredNewObjects(ObjectBuilder.java:1964)
    at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.discoverAndPersistUnregisteredNewObjects(UnitOfWorkImpl.java:4178)
    at org.eclipse.persistence.mappings.ObjectReferenceMapping.cascadeDiscoverAndPersistUnregisteredNewObjects(ObjectReferenceMapping.java:938)
    at org.eclipse.persistence.mappings.ObjectReferenceMapping.cascadeDiscoverAndPersistUnregisteredNewObjects(ObjectReferenceMapping.java:916)
    at org.eclipse.persistence.internal.descriptors.ObjectBuilder.cascadeDiscoverAndPersistUnregisteredNewObjects(ObjectBuilder.java:1964)
    at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.discoverAndPersistUnregisteredNewObjects(UnitOfWorkImpl.java:4178)
    at org.eclipse.persistence.mappings.CollectionMapping.cascadeDiscoverAndPersistUnregisteredNewObjects(CollectionMapping.java:426)
    at org.eclipse.persistence.internal.descriptors.ObjectBuilder.cascadeDiscoverAndPersistUnregisteredNewObjects(ObjectBuilder.java:1964)
    at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.discoverAndPersistUnregisteredNewObjects(UnitOfWorkImpl.java:4178)
    at org.eclipse.persistence.mappings.ObjectReferenceMapping.cascadeDiscoverAndPersistUnregisteredNewObjects(ObjectReferenceMapping.java:938)
    at org.eclipse.persistence.mappings.ObjectReferenceMapping.cascadeDiscoverAndPersistUnregisteredNewObjects(ObjectReferenceMapping.java:916)
    at org.eclipse.persistence.internal.descriptors.ObjectBuilder.cascadeDiscoverAndPersistUnregisteredNewObjects(ObjectBuilder.java:1964)
    at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.discoverAndPersistUnregisteredNewObjects(UnitOfWorkImpl.java:4178)
    at org.eclipse.persistence.mappings.CollectionMapping.cascadeDiscoverAndPersistUnregisteredNewObjects(CollectionMapping.java:426)
    at org.eclipse.persistence.internal.descriptors.ObjectBuilder.cascadeDiscoverAndPersistUnregisteredNewObjects(ObjectBuilder.java:1964)
    at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.discoverAndPersistUnregisteredNewObjects(UnitOfWorkImpl.java:4178)
4

0 に答える 0