1

I am using the Amdatu implementation of Eclipselink for OSGI compatibility.

Can anyone spot why this is not working?

The class below is defined as an Entity and should be persisted. Every time an update is made to the Ptz2PlPalletUnloadOrder, the save method in OrderRepoImpl merges the persisted order with an updated version where the Ptz2PlPalletUnloadDefinition def or the OrderState orderState has been changed.

Anyways, I am able to update the orderState in the database using the em.merge method, but I cannot update the @Embedded def Object in the BD. Updating without making a new row in the database is highly preferred.

When merging the object no exception is thrown, the log4j is included at the bottom of the question.

Ptz2PlPalletUnloadOrder

@Entity(name = Ptz2PlPalletUnloadOrder.TABLE_NAME)
@Table(name = Ptz2PlPalletUnloadOrder.TABLE_NAME)
public class Ptz2PlPalletUnloadOrder implements Order {
    public static final String TYPE = "ptz2pl.pallet.unload";
    public static final String TABLE_NAME = "order_ptz2pl_pallet_unload";

    // Order ID
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private long dbId;

    @Temporal(TemporalType.TIMESTAMP)
    private Date created = new Date();

    // States
    @Enumerated(EnumType.STRING)
    private OrderState orderState = OrderState.NEW;

    @Embedded
    private Ptz2PlPalletUnloadDefinition def;
}

Ptz2PlPalletUnloadDefinition

The persisted class.

@Embeddable
public class Ptz2PlPalletUnloadDefinition {

    @Embedded
    private Station station;
    private volatile Integer agvId;
    private volatile String agvSystemName;
    @Temporal(TemporalType.TIMESTAMP)
    private Date deadLine;
    private String userId;
    private Long palletType;

    private Ptz2PlPalletUnloadDefinition() {

    }
}

OrderRepoImpl

@Transactional
@Component(provide = ManagedTransactional.class)
public class OrderRepoImpl implements OrderRepo, ManagedTransactional {

    private EntityManager em;

    @Override
    public Ptz2PlPalletUnloadOrder save(Ptz2PlPalletUnloadOrder order) {
        Ptz2PlPalletUnloadOrder result = em.merge(order);
        return result;
    }
}

When braking through this method, the result value has the correct values. So one would expect that the database has been updated, but this unfortunate does not happen when the to be updated field of Ptz2PlPalletUnloadOrder is an embedded object.

Log

[EL Finer]: 2016-02-09 15:25:32.393--ServerSession(1465675217)--Thread(Thread[pool-7-thread-4,5,Configuration Admin Service])--client acquired: 2038620953
[EL Finer]: 2016-02-09 15:25:32.393--UnitOfWork(769186)--Thread(Thread[pool-7-thread-4,5,Configuration Admin Service])--TX binding to tx mgr, status=STATUS_ACTIVE
[EL Finer]: 2016-02-09 15:25:32.394--ClientSession(2038620953)--Thread(Thread[pool-7-thread-4,5,Configuration Admin Service])--acquire unit of work: 769186
[EL Finest]: 2016-02-09 15:25:32.395--UnitOfWork(769186)--Thread(Thread[pool-7-thread-4,5,Configuration Admin Service])--Merge clone with references Ptz2PlPalletUnloadOrder [id=1, orderState=QUEUED, location=Location [stationId=10, systemName=BEING], allocatedAgvId=null, allocatedAgvSystemName=null]
[EL Finer]: 2016-02-09 15:25:37.014--UnitOfWork(769186)--Thread(Thread[pool-7-thread-4,5,Configuration Admin Service])--TX beforeCompletion callback, status=STATUS_ACTIVE
[EL Finer]: 2016-02-09 15:25:37.015--UnitOfWork(769186)--Thread(Thread[pool-7-thread-4,5,Configuration Admin Service])--begin unit of work commit
[EL Finer]: 2016-02-09 15:25:37.016--UnitOfWork(769186)--Thread(Thread[pool-7-thread-4,5,Configuration Admin Service])--TX afterCompletion callback, status=COMMITTED
[EL Finer]: 2016-02-09 15:25:37.017--UnitOfWork(769186)--Thread(Thread[pool-7-thread-4,5,Configuration Admin Service])--end unit of work commit
[EL Finer]: 2016-02-09 15:25:37.018--UnitOfWork(769186)--Thread(Thread[pool-7-thread-4,5,Configuration Admin Service])--release unit of work
[EL Finer]: 2016-02-09 15:25:37.019--ClientSession(2038620953)--Thread(Thread[pool-7-thread-4,5,Configuration Admin Service])--client released
Wafje
  • 103
  • 1
  • 6
  • `allocatedAgvId` and `allocatedAgvSystemName` are set to null so the definition is being updated. I suspect those are the only fields that have changed (since they're marked as volatile). – Thomas Feb 09 '16 at 14:33
  • @Thomas I think I phrased my question wrong and rephrased it. I want to update the persisted (database) object when either `OrderState orderState` or `Ptz2PlPalletUnloadDefinition` def has been changed. It does work on the first variable, but not on the latter. – Wafje Feb 09 '16 at 15:19
  • 1
    Could you provide an example of changing `def`? Just replacing the instance with another equal instance (same values) shouldn't result in any change since effectively the def is still the same. – Thomas Feb 09 '16 at 16:34
  • @Thomas The `palletType` and `station` in def will in some cases not have a value (null) when the def is initialized. Their values will be null in the DB. When the `Order` gets 'started', the values are fetched from another source and the order should get updated. Starting the `Order` will also update the `orderState` from state NEW to ACTIVE which happens. – Wafje Feb 09 '16 at 20:49
  • How are you fetching and changing values? – Chris Feb 10 '16 at 13:36

1 Answers1

2

I've reproduced this in an amdatu-jpa testcase.

Found a similar question on the EclipseLink forum https://www.eclipse.org/forums/index.php/t/474144/

Disabling weaving resolves the issue in the test I've created. To disable add the property below to persistence.xml

<property name="eclipselink.weaving" value="false"/>
  • Thank you! Disabling weaving did indeed resolve the issue. I filed an issue on the EcliseLink issuetracker. https://bugs.eclipse.org/bugs/show_bug.cgi?id=487592 . Or do you think this is indented? What does weaving do exactly? – Wafje Feb 10 '16 at 15:31
  • Weaving in this case is likely enabling change tracking, allowing a performance boost as deferred change tracking requires keeping a backup copy and using it as a comparison for changes. There are other performance options enabled through weaving though, so you may want to keep it and try setting the change tracking option to 'deferred' for the problem entity as described here http://www.eclipse.org/eclipselink/documentation/2.5/jpa/extensions/a_changetracking.htm – Chris Feb 10 '16 at 16:02