We have a pretty old TopLink config Project in which a Customer, trade and tradecode objects defined as parent-child (oneToMany).
Whenever we change a trade code the code is getting updated in the trade table. This change is reflecting on the other customers, who are referring this trade code. This is how its built.
TOPLink.Public.PublicInterface.Descriptor descriptor = new TOPLink.Public.PublicInterface.Descriptor();
Vector vector = new Vector();
mapping = new TOPLink.Public.Mappings.DirectToFieldMapping();
Users can change the trade code from UI. It is getting updated the trade code for that tradeCodeId.
Now we need to update the tradeCodeId for this customer. we need to search for a matching codeId and replace with that codeId, if not create a new one and update with the new Id. Can this be done using the config?
Thanks a bunch.
I'm not sure of your background or experience with TopLink, but the old TOPLink config you are using should work and look pretty similar to the Oracle TopLink or native EclipseLink config.
What I'm missing from your description is what you mean when you discuss what you change and works vs the changes you need to perform now. You only show the Trade object and its "tradeCodeId" pk, so I can only guess what you mean when you say you want to update a tradeCodeId for the customer. Do you mean that the Customer table has a tradeCodeId or a reference to a Trade object?
As long as the field is not appart of the primary key, it should be able to be changed. The only problem I forsee you might encounter is with creating a new Trade instance and persisting it in the database - the primary key mapping for tradeCodeId has setIsReadOnly(true) called on it, which might cause problems in trying to set this value.
Other than that, you would just use an expression query in the same way the application might look up a customer now. Something like:
ReadQuery query = new ReadObjectQuery(Trade.class);
Vector arguments = new Vector();
Trade trade = (Trade)session.executeQuery(query, arguments);