1

カスタムトランスフォーマーを使用して、このSupplierOrderChargeオブジェクトの一種の集計を作成しようとしています。ここで、リスト内のすべての値を合計します。

トランスフォーマーのアノテーションを削除すると、以下の例外はなくなります。これは有効な構成ですか?このようなゲッターメソッド用のトランスを置くことはできますか?それともMOXyのバグでしょうか?

これは私のコードです:

@XmlElement
@XmlTransformation
@XmlReadTransformer(transformerClass = GeneralAttributeMarkerTransformer.class)
@XmlWriteTransformers({ @XmlWriteTransformer(xmlPath = "ORDER_HEADER/SHIPPING_INFO/SHIPMENT_CODE/text()", transformerClass = ShippingInfoTransformer.class),
@XmlWriteTransformer(xmlPath = "ORDER_HEADER/SHIPPING_INFO/SHIPPING_COST_EX_VAT/text()", transformerClass = ShippingInfoTransformer.class),
@XmlWriteTransformer(xmlPath = "ORDER_HEADER/SHIPPING_INFO/SHIPPING_COST_VAT/text()", transformerClass = ShippingInfoTransformer.class),
@XmlWriteTransformer(xmlPath = "ORDER_HEADER/SHIPPING_INFO/SHIPPING_COST_INC_VAT/text()", transformerClass = ShippingInfoTransformer.class), })
@Transient
protected SupplierOrderCharge getShippingInfo() {
    for (final SupplierOrderCharge soCharge : getOrderCharges()) {
        if (EntryType.SHIPPING.equals(soCharge.getEntryType())) {
            return soCharge;
        }
    }
    return null;
}

この例外が発生します:

javax.xml.bind.JAXBException: 
Descriptor Exceptions: 
---------------------------------------------------------

Exception [EclipseLink-60] (Eclipse Persistence Services - 2.4.0.v20120608-r11652): org.eclipse.persistence.exceptions.DescriptorException
Exception Description: The method [] or [getShippingInfo] is not defined in the object [com.debijenkorf.data.model.supplier.SupplierOrder].
Internal Exception: java.lang.NoSuchMethodException: com.debijenkorf.data.model.supplier.SupplierOrder.(com.debijenkorf.data.model.supplier.SupplierOrderCharge)
Mapping: org.eclipse.persistence.oxm.mappings.XMLTransformationMapping[shippingInfo]
Descriptor: XMLDescriptor(com.debijenkorf.data.model.supplier.SupplierOrder --> [DatabaseTable(SALES_ORDER)])

Runtime Exceptions: 
---------------------------------------------------------

java.lang.NullPointerException

- with linked exception:
[Exception [EclipseLink-0] (Eclipse Persistence Services - 2.4.0.v20120608-r11652): org.eclipse.persistence.exceptions.IntegrityException
Descriptor Exceptions: 
---------------------------------------------------------

Exception [EclipseLink-60] (Eclipse Persistence Services - 2.4.0.v20120608-r11652): org.eclipse.persistence.exceptions.DescriptorException
Exception Description: The method [] or [getShippingInfo] is not defined in the object [com.debijenkorf.data.model.supplier.SupplierOrder].
Internal Exception: java.lang.NoSuchMethodException: com.debijenkorf.data.model.supplier.SupplierOrder.(com.debijenkorf.data.model.supplier.SupplierOrderCharge)
Mapping: org.eclipse.persistence.oxm.mappings.XMLTransformationMapping[shippingInfo]
Descriptor: XMLDescriptor(com.debijenkorf.data.model.supplier.SupplierOrder --> [DatabaseTable(SALES_ORDER)])

Runtime Exceptions: 
---------------------------------------------------------

java.lang.NullPointerException
]
at org.eclipse.persistence.jaxb.JAXBContext$ContextPathInput.createContextState(JAXBContext.java:771)
at org.eclipse.persistence.jaxb.JAXBContext$ContextPathInput.createContextState(JAXBContext.java:711)
at org.eclipse.persistence.jaxb.JAXBContext.<init>(JAXBContext.java:157)
at org.eclipse.persistence.jaxb.JAXBContextFactory.createContext(JAXBContextFactory.java:134)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:128)
at javax.xml.bind.ContextFinder.find(ContextFinder.java:249)
at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:372)
at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:337)
at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:244)
at com.debijenkorf.services.core.JaxbMoxyMarUn.marshal(JaxbMoxyMarUn.java:48)
at com.debijenkorf.services.fc4.JaxbMarUnFC1Test.testMarshal(JaxbMarUnFC1Test.java:36)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:69)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:48)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
at org.junit.runners.ParentRunner.run(ParentRunner.java:292)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Caused by: Exception [EclipseLink-0] (Eclipse Persistence Services - 2.4.0.v20120608-r11652): org.eclipse.persistence.exceptions.IntegrityException
Descriptor Exceptions: 
---------------------------------------------------------

Exception [EclipseLink-60] (Eclipse Persistence Services - 2.4.0.v20120608-r11652): org.eclipse.persistence.exceptions.DescriptorException
Exception Description: The method [] or [getShippingInfo] is not defined in the object [com.debijenkorf.data.model.supplier.SupplierOrder].
Internal Exception: java.lang.NoSuchMethodException: com.debijenkorf.data.model.supplier.SupplierOrder.(com.debijenkorf.data.model.supplier.SupplierOrderCharge)
Mapping: org.eclipse.persistence.oxm.mappings.XMLTransformationMapping[shippingInfo]
Descriptor: XMLDescriptor(com.debijenkorf.data.model.supplier.SupplierOrder --> [DatabaseTable(SALES_ORDER)])

Runtime Exceptions: 
---------------------------------------------------------

java.lang.NullPointerException

at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.initializeDescriptors(DatabaseSessionImpl.java:638)
at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.initializeDescriptors(DatabaseSessionImpl.java:574)
at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.initializeDescriptors(DatabaseSessionImpl.java:533)
at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.postConnectDatasource(DatabaseSessionImpl.java:777)
at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.login(DatabaseSessionImpl.java:735)
at org.eclipse.persistence.oxm.XMLContext$XMLContextState.<init>(XMLContext.java:857)
at org.eclipse.persistence.oxm.XMLContext$XMLContextState.<init>(XMLContext.java:832)
at org.eclipse.persistence.oxm.XMLContext.<init>(XMLContext.java:193)
at org.eclipse.persistence.jaxb.JAXBContext$ContextPathInput.createContextState(JAXBContext.java:797)
at org.eclipse.persistence.jaxb.JAXBContext$ContextPathInput.createContextState(JAXBContext.java:769)
... 37 more
4

1 に答える 1

1

ここにバグがある可能性があります。以下のリンクから入力していただけませんか。発生している問題を示す例を提供できますか?

を正しく作成するサンプルコードを以下に追加XmlTransformationMappingしました。私は次のことをしました:

  • @XmlElement注釈を削除しました。
  • メソッドgetShippingInfo()を公開しました。
  • メソッドを追加しましたsetShippingInfo(SupplierOrderCharge s)
package forum13075432;

import java.util.List;
import org.eclipse.persistence.oxm.annotations.*;

public class Root {

    @XmlTransformation
    @XmlReadTransformer(transformerClass = GeneralAttributeMarkerTransformer.class)
    @XmlWriteTransformers({
            @XmlWriteTransformer(xmlPath = "ORDER_HEADER/SHIPPING_INFO/SHIPMENT_CODE/text()", transformerClass = ShippingInfoTransformer.class),
            @XmlWriteTransformer(xmlPath = "ORDER_HEADER/SHIPPING_INFO/SHIPPING_COST_EX_VAT/text()", transformerClass = ShippingInfoTransformer.class),
            @XmlWriteTransformer(xmlPath = "ORDER_HEADER/SHIPPING_INFO/SHIPPING_COST_VAT/text()", transformerClass = ShippingInfoTransformer.class),
            @XmlWriteTransformer(xmlPath = "ORDER_HEADER/SHIPPING_INFO/SHIPPING_COST_INC_VAT/text()", transformerClass = ShippingInfoTransformer.class), })
    public SupplierOrderCharge getShippingInfo() {
        for (final SupplierOrderCharge soCharge : getOrderCharges()) {
            if (EntryType.SHIPPING.equals(soCharge.getEntryType())) {
                return soCharge;
            }
        }
        return null;
    }

    public void setShippingInfo(SupplierOrderCharge s) {
    }

    private List<SupplierOrderCharge> getOrderCharges() {
        // TODO Auto-generated method stub
        return null;
    }

}
于 2012-10-25T20:36:34.777 に答える