Eclipselink DescriptorEventListener多次调用

时间:2015-02-16 08:28:11

标签: jpa event-handling eclipselink

我有这个实体:

@Entity
@Customizer(TestCustomizer.class)
public class Action extends IntermediateUnit
{
    ...
}

和这个定制工具:

public class TestCustomizer implements DescriptorCustomizer
{
    private static final Logger logger = LoggerFactory.getLogger(TestCustomizer.class);

    @Override
    public void customize(ClassDescriptor descriptor)
    {
        descriptor.getEventManager().addListener(new TestEventListener());
    }

    public static class TestEventListener extends DescriptorEventAdapter
    {
        @Override
        public void preWrite(DescriptorEvent event)
        {
            logger.debug("event.getObject(): {}", event.getObject());
            logger.debug("event.getOriginalObject(): {}", event.getOriginalObject());
            logger.debug("event.getSource(): {}", event.getSource());
            logger.debug("event.getChangeSet(): {}", event.getChangeSet());
            logger.debug("event.getClassDescriptor(): {}", event.getClassDescriptor());
            logger.debug("event.getDescriptor(): {}", event.getDescriptor());
            logger.debug("event.getEventCode(): {}", event.getEventCode());
            logger.debug("event.getQuery(): {}", event.getQuery());
            logger.debug("event.getRecord(): {}", event.getRecord());
            logger.debug("event.getSession(): {}", event.getSession());
        }

        // all other event listeners methods are the same
    }
}

现在当我更新这个实体时,会多次调用侦听器:

TestCustomizer.preWrite[:26] - event.getObject(): it.shape.edea2.jpa.Action@93dd0cb9[473284@8]
TestCustomizer.preWrite[:27] - event.getOriginalObject(): it.shape.edea2.jpa.Action@93dd0cb9[473284@8]
TestCustomizer.preWrite[:28] - event.getSource(): it.shape.edea2.jpa.Action@93dd0cb9[473284@8]
TestCustomizer.preWrite[:29] - event.getChangeSet(): null
TestCustomizer.preWrite[:30] - event.getClassDescriptor(): RelationalDescriptor(it.shape.edea2.jpa.Action --> [DatabaseTable(UNIT)])
TestCustomizer.preWrite[:31] - event.getDescriptor(): RelationalDescriptor(it.shape.edea2.jpa.Action --> [DatabaseTable(UNIT)])
TestCustomizer.preWrite[:32] - event.getEventCode(): 0
TestCustomizer.preWrite[:33] - event.getQuery(): WriteObjectQuery(it.shape.edea2.jpa.Action@93dd0cb9[473284@8])
TestCustomizer.preWrite[:34] - event.getRecord(): null
TestCustomizer.preWrite[:35] - event.getSession(): UnitOfWork(
    DatabaseAccessor(connected)
    MySQLPlatform)
TestCustomizer.preUpdate[:71] - event.getObject(): it.shape.edea2.jpa.Action@93dd0cb9[473284@8]
TestCustomizer.preUpdate[:72] - event.getOriginalObject(): it.shape.edea2.jpa.Action@93dd0cb9[473284@8]
TestCustomizer.preUpdate[:73] - event.getSource(): it.shape.edea2.jpa.Action@93dd0cb9[473284@8]
TestCustomizer.preUpdate[:74] - event.getChangeSet(): null
TestCustomizer.preUpdate[:75] - event.getClassDescriptor(): RelationalDescriptor(it.shape.edea2.jpa.Action --> [DatabaseTable(UNIT)])
TestCustomizer.preUpdate[:76] - event.getDescriptor(): RelationalDescriptor(it.shape.edea2.jpa.Action --> [DatabaseTable(UNIT)])
TestCustomizer.preUpdate[:77] - event.getEventCode(): 6
TestCustomizer.preUpdate[:78] - event.getQuery(): WriteObjectQuery(it.shape.edea2.jpa.Action@93dd0cb9[473284@8])
TestCustomizer.preUpdate[:79] - event.getRecord(): null
TestCustomizer.preUpdate[:80] - event.getSession(): UnitOfWork(
    DatabaseAccessor(connected)
    MySQLPlatform)
TestCustomizer.preUpdateWithChanges[:86] - event.getObject(): it.shape.edea2.jpa.Action@93dd0cb9[473284@8]
TestCustomizer.preUpdateWithChanges[:87] - event.getOriginalObject(): it.shape.edea2.jpa.Action@93dd0cb9[473284@8]
TestCustomizer.preUpdateWithChanges[:88] - event.getSource(): it.shape.edea2.jpa.Action@93dd0cb9[473284@8]
TestCustomizer.preUpdateWithChanges[:89] - event.getChangeSet(): null
TestCustomizer.preUpdateWithChanges[:90] - event.getClassDescriptor(): RelationalDescriptor(it.shape.edea2.jpa.Action --> [DatabaseTable(UNIT)])
TestCustomizer.preUpdateWithChanges[:91] - event.getDescriptor(): RelationalDescriptor(it.shape.edea2.jpa.Action --> [DatabaseTable(UNIT)])
TestCustomizer.preUpdateWithChanges[:92] - event.getEventCode(): 17
TestCustomizer.preUpdateWithChanges[:93] - event.getQuery(): UpdateObjectQuery(it.shape.edea2.jpa.Action@93dd0cb9[473284@8])
TestCustomizer.preUpdateWithChanges[:94] - event.getRecord(): null
TestCustomizer.preUpdateWithChanges[:95] - event.getSession(): UnitOfWork(
    DatabaseAccessor(connected)
    MySQLPlatform)
TestCustomizer.aboutToUpdate[:101] - event.getObject(): it.shape.edea2.jpa.Action@93dd0cb9[473284@9]
TestCustomizer.aboutToUpdate[:102] - event.getOriginalObject(): it.shape.edea2.jpa.Action@93dd0cb9[473284@8]
TestCustomizer.aboutToUpdate[:103] - event.getSource(): it.shape.edea2.jpa.Action@93dd0cb9[473284@9]
TestCustomizer.aboutToUpdate[:104] - event.getChangeSet(): null
TestCustomizer.aboutToUpdate[:105] - event.getClassDescriptor(): RelationalDescriptor(it.shape.edea2.jpa.Action --> [DatabaseTable(UNIT)])
TestCustomizer.aboutToUpdate[:106] - event.getDescriptor(): RelationalDescriptor(it.shape.edea2.jpa.Action --> [DatabaseTable(UNIT)])
TestCustomizer.aboutToUpdate[:107] - event.getEventCode(): 13
TestCustomizer.aboutToUpdate[:108] - event.getQuery(): UpdateObjectQuery(it.shape.edea2.jpa.Action@93dd0cb9[473284@9])
TestCustomizer.aboutToUpdate[:109] - event.getRecord(): DatabaseRecord(
    UNIT.NAME => asdasdasdasdasd asd asd asd
    UNIT.VERSION => 9)
TestCustomizer.aboutToUpdate[:110] - event.getSession(): UnitOfWork(
    DatabaseAccessor(connected)
    MySQLPlatform)
TestCustomizer.preWrite[:26] - event.getObject(): it.shape.edea2.jpa.Action@93dd0cb9[473284@9]
TestCustomizer.preWrite[:27] - event.getOriginalObject(): it.shape.edea2.jpa.Action@93dd0cb9[473284@8]
TestCustomizer.preWrite[:28] - event.getSource(): it.shape.edea2.jpa.Action@93dd0cb9[473284@9]
TestCustomizer.preWrite[:29] - event.getChangeSet(): null
TestCustomizer.preWrite[:30] - event.getClassDescriptor(): RelationalDescriptor(it.shape.edea2.jpa.Action --> [DatabaseTable(UNIT)])
TestCustomizer.preWrite[:31] - event.getDescriptor(): RelationalDescriptor(it.shape.edea2.jpa.Action --> [DatabaseTable(UNIT)])
TestCustomizer.preWrite[:32] - event.getEventCode(): 0
TestCustomizer.preWrite[:33] - event.getQuery(): WriteObjectQuery(it.shape.edea2.jpa.Action@93dd0cb9[473284@9])
TestCustomizer.preWrite[:34] - event.getRecord(): null
TestCustomizer.preWrite[:35] - event.getSession(): UnitOfWork(
    DatabaseAccessor(connected)
    MySQLPlatform)
TestCustomizer.preUpdate[:71] - event.getObject(): it.shape.edea2.jpa.Action@93dd0cb9[473284@9]
TestCustomizer.preUpdate[:72] - event.getOriginalObject(): it.shape.edea2.jpa.Action@93dd0cb9[473284@8]
TestCustomizer.preUpdate[:73] - event.getSource(): it.shape.edea2.jpa.Action@93dd0cb9[473284@9]
TestCustomizer.preUpdate[:74] - event.getChangeSet(): null
TestCustomizer.preUpdate[:75] - event.getClassDescriptor(): RelationalDescriptor(it.shape.edea2.jpa.Action --> [DatabaseTable(UNIT)])
TestCustomizer.preUpdate[:76] - event.getDescriptor(): RelationalDescriptor(it.shape.edea2.jpa.Action --> [DatabaseTable(UNIT)])
TestCustomizer.preUpdate[:77] - event.getEventCode(): 6
TestCustomizer.preUpdate[:78] - event.getQuery(): WriteObjectQuery(it.shape.edea2.jpa.Action@93dd0cb9[473284@9])
TestCustomizer.preUpdate[:79] - event.getRecord(): null
TestCustomizer.preUpdate[:80] - event.getSession(): UnitOfWork(
    DatabaseAccessor(connected)
    MySQLPlatform)
TestCustomizer.preWrite[:26] - event.getObject(): it.shape.edea2.jpa.Action@93dd0cb9[473284@9]
TestCustomizer.preWrite[:27] - event.getOriginalObject(): it.shape.edea2.jpa.Action@93dd0cb9[473284@9]
TestCustomizer.preWrite[:28] - event.getSource(): it.shape.edea2.jpa.Action@93dd0cb9[473284@9]
TestCustomizer.preWrite[:29] - event.getChangeSet(): null
TestCustomizer.preWrite[:30] - event.getClassDescriptor(): RelationalDescriptor(it.shape.edea2.jpa.Action --> [DatabaseTable(UNIT)])
TestCustomizer.preWrite[:31] - event.getDescriptor(): RelationalDescriptor(it.shape.edea2.jpa.Action --> [DatabaseTable(UNIT)])
TestCustomizer.preWrite[:32] - event.getEventCode(): 0
TestCustomizer.preWrite[:33] - event.getQuery(): WriteObjectQuery(it.shape.edea2.jpa.Action@93dd0cb9[473284@9])
TestCustomizer.preWrite[:34] - event.getRecord(): null
TestCustomizer.preWrite[:35] - event.getSession(): UnitOfWork(
    DatabaseAccessor(connected)
    MySQLPlatform)
TestCustomizer.preUpdate[:71] - event.getObject(): it.shape.edea2.jpa.Action@93dd0cb9[473284@9]
TestCustomizer.preUpdate[:72] - event.getOriginalObject(): it.shape.edea2.jpa.Action@93dd0cb9[473284@9]
TestCustomizer.preUpdate[:73] - event.getSource(): it.shape.edea2.jpa.Action@93dd0cb9[473284@9]
TestCustomizer.preUpdate[:74] - event.getChangeSet(): null
TestCustomizer.preUpdate[:75] - event.getClassDescriptor(): RelationalDescriptor(it.shape.edea2.jpa.Action --> [DatabaseTable(UNIT)])
TestCustomizer.preUpdate[:76] - event.getDescriptor(): RelationalDescriptor(it.shape.edea2.jpa.Action --> [DatabaseTable(UNIT)])
TestCustomizer.preUpdate[:77] - event.getEventCode(): 6
TestCustomizer.preUpdate[:78] - event.getQuery(): WriteObjectQuery(it.shape.edea2.jpa.Action@93dd0cb9[473284@9])
TestCustomizer.preUpdate[:79] - event.getRecord(): null
TestCustomizer.preUpdate[:80] - event.getSession(): UnitOfWork(
    DatabaseAccessor(connected)
    MySQLPlatform)

我需要为每次更新实体添加一个关系。

@EntityListeners不是一个选项,因为我需要添加一个关系。

请注意,我无法在preUpdateWithChanges中添加关系,级联持续似乎为时已晚。

那么,如何知道是否已经为此更新操作调用了侦听器?

谢谢

0 个答案:

没有答案