Private Owned, Conform Results in Unit Of Work, ...
I'd like to have some precision on Private Owned, Conform Results in Unit Of Work, Use joining, Use Batch Reading, ...
Thank in advance
Think of Private Owned as "if I delete the source, should I delete the target". So if you have a 1-1 between Customer and Address, if you delete a customer, should you delete their associated address automatically? If so, then it's private owned.
If you have a 1-M, say a Manager has 1-M to ManagedEmployees, if you remove a ManagedEmployee from a manager, should it be deleted from the database? Probably not, you may simply be assigning them to another Manager... So, it's probably not private owned.
Don't use the Conform Results in Unit Of Work in the mapping work bench, that sets up a default behavior for queries on that class, and I prefer to set it as needed, not globally. Conforming a query is unit of work related. Imagine you have a UnitOfWork and then query for all Customers from "Ottawa". Imagine you get back 5 from the database. Then in the unit of work you change one of the customers from "Ottawa" to "Kanata". Then you query the unit of work again (before committing) to find all customers in "Ottawa". The default behavior of TopLink would be to return the customer that has moved to "Kanata", because as far as the database is concerned you haven't committed the change, so he's still technically in Ottawa. If you turned on conforming for that class, or for the specific query, then you would NOT get the customer that moved (at a performance cost, of course).
The docs on Join/Batch reading are pretty good, see 6-6 of the Using TopLink manual in the optimization section. The option in the mapping workbench lets you setup defaults for the relationship, but again, my preference has always been to set it on a per query basis... This gives you a way to centralize the default behavior for batching and joining for certain relationships.
- Don
Similar Messages
-
Disadvantages of 'Conform Results'
In order to be able to retrieve newly created objects from a UnitOfWork, we have set the 'Conform Results in Unit of Work' to true on all of our descriptors. Whenever I send these descriptors to Oracle (e.g. in a TAR or posted here), I always get a comment like: "Oh, we don't recommend that, why don't you just set that option per query? Well, we prefer not to have to know whether the object we are looking for is new or not. So I'm wondering what are the disadvantages of using this setting as our default? Is it just a matter of performance?
You wrote "every query". Does this also include queries that only use the primary key (findByPK). I thought that TopLink could handle this situation without flushing the cache towards the database. Some clarification,
1 - If conforming is not used, the query will only query the state of the database, even for primary key queries.
2 - TopLink does not do conforming by flushing the changes to the database, TopLink conform by query the unit of work state in memory.
In general you must use conforming to query new or changed objects in the unit of work.
For primary key queries, there is also another option, which I believe Donald was referring to. You can set,
unitOfWork.setShouldNewObjectsBeCached(true);
on the unit of work to cache new objects, by default TopLink does not cache new objects (as they typically do not get primary keys until commit).
To use this you must ensure that the object is assign its primary key "before" it is registered.
i.e.
unitOfWork.assignSequenceNumber(newObject);
newObjectClone = unitOfWork.registerObject(newObject);
If you are using EJB CMP, then new objects are cached in the unit of work by default (as the spec requires their primary key to be assign in create). So you would not need to conform findByPrimaryKey when using CMP.
In 10.1.3 a writeChanges() API has been added to the unit of work, that allows writing of the unit of work changes early. This could potentially also be used as an alternative to using conforming. -
Private owned delete not working
Hi
I am stumped by a problem trying to delete a child object from a parent's collection.
I have set Private Owned on for the 1-many mapping, but when I remove the privately owned child from the parent and commit, no DELETE SQL is produced. The only difference from classes that I can delete by removing from the parent is that my child class does not specify direct-mapped primary keys, but rather references to the parent objects:
public class ServiceAsset extends ServiceAssetValue implements Ownable {
private Service service;
private AssetType assetType;
Here are the steps I use to remove the child:
public void delete(AssetType assetTypeProto, Service serviceProto) throws PersistenceException {
Service service = (Service)TopLinkSession.getServerSessionInstance().acquireClientSession().readObject(serviceProto);
AssetType assetType = (AssetType)TopLinkSession.getServerSessionInstance().acquireClientSession().readObject(assetTypeProto);
this.getWriteSession().logMessages();
ServiceAsset serviceAsset = new ServiceAsset();
serviceAsset.setService(service);
serviceAsset.setAssetType(assetType);
serviceAsset = (ServiceAsset)TopLinkSession.getServerSessionInstance().acquireClientSession().readObject(serviceAsset);
ServiceAsset workingCopyServiceAsset = (ServiceAsset)getUnitOfWork().registerExistingObject(serviceAsset);
Service workingCopyService = (Service)getUnitOfWork().registerExistingObject(service);
workingCopyService.getServiceAssets().remove(workingCopyServiceAsset);
this.getUnitOfWork().printRegisteredObjects();
commit();
Here is the mapping specification in the parent descriptor:
<database-mapping>
<attribute-name>serviceAssets</attribute-name>
<read-only>false</read-only>
<reference-class>com.xxxx.ServiceAsset</reference-class>
<is-private-owned>true</is-private-owned>
<uses-batch-reading>false</uses-batch-reading>
<indirection-policy>
<mapping-indirection-policy>
<type>oracle.toplink.internal.indirection.TransparentIndirectionPolicy</type>
</mapping-indirection-policy>
</indirection-policy>
<container-policy>
<mapping-container-policy>
<container-class>oracle.toplink.indirection.IndirectList</container-class>
<type>oracle.toplink.internal.queryframework.ListContainerPolicy</type>
</mapping-container-policy>
</container-policy>
<source-key-fields>
<field>SERVICES.SERVICEID</field>
</source-key-fields>
<target-foreign-key-fields>
<field>SERVICEASSETS.SERVICEID</field>
</target-foreign-key-fields>
<type>oracle.toplink.mappings.OneToManyMapping</type>
</database-mapping>
Is there an obvious mistake I am making?
James
p.s. The debug output from Toplink is
ServerSession(9727266)--client acquired
ClientSession(26675936)--Execute query ReadObjectQuery(com.xxx.ServiceAsset)
ClientSession(23126121)--acquire unit of work: 21690871
UnitOfWork(21690871)--Register the existing object com.xxx.ServiceAsset@12d26d2
UnitOfWork(21690871)--Register the existing object com.xxx.AssetType@43487e
UnitOfWork(21690871)--Register the existing object com.xxx.Service@4a96a
UnitOfWork(21690871)--Register the existing object com.xxx.ServiceProvider@974600
UnitOfWork(21690871)--Register the existing object com.xxx.Application@c3e967
UnitOfWork(21690871)--Register the existing object com.xxx.Domain@1b963c4
UnitOfWork(21690871)--Register the existing object com.xxx.Service@4a96a
UnitOfWork(21690871)--Register the existing object com.xxx.DomainUrl@1ef3ccd
UnitOfWork(21690871)--Register the existing object com.xxx.Domain@1b963c4
UnitOfWork(21690871)--Register the existing object com.xxx.StatusType@166aab6
UnitOfWork(21690871)--Register the existing object com.xxx.Service@4a96a
UnitOfWork(21690871)--Register the existing object com.xxx.ServiceAsset@12d26d2
UnitOfWork(21690871)--Register the existing object com.xxx.ServiceAsset@f77511
UnitOfWork(21690871)--Register the existing object com.xxx.AssetType@2eef15
UnitOfWork(21690871)--Register the existing object com.xxx.Service@4a96a
UnitOfWork(21690871)--Register the existing object com.xxx.ServiceAsset@a974c7
UnitOfWork(21690871)--Register the existing object com.xxx.AssetType@3526cf
UnitOfWork(21690871)--Register the existing object com.xxx.Service@4a96a
UnitOfWork(21690871)--Register the existing object com.xxx.ServiceAsset@150f0a7
UnitOfWork identity hashcode: 21690871
Deleted Objects:
All Registered Clones:
Key: [111] Identity Hash Code:4521906 Object: com.xxx.Domain@44ffb2
Key: [2] Identity Hash Code:22185277 Object: com.xxx.AssetType@152853d
Key: [1] Identity Hash Code:24431393 Object: com.xxx.ServiceProvider@174cb21
Key: [1 11] Identity Hash Code:22007194 Object: com.xxx.ServiceAsset@14fcd9a
Key: [653] Identity Hash Code:25228613 Object: com.xxx.DomainUrl@180f545
Key: [1] Identity Hash Code:21789336 Object: com.xxx.AssetType@14c7a98
Key: [0] Identity Hash Code:1079807 Object: com.xxx.Application@1079ff
Key: [R] Identity Hash Code:22129680 Object: com.xxx.StatusType@151ac10
Key: [11] Identity Hash Code:954895 Object: com.xxx.Service@e920f
Key: [2 11] Identity Hash Code:2547660 Object: com.xxx.ServiceAsset@26dfcc
Key: [5] Identity Hash Code:25619834 Object: com.xxx.AssetType@186ed7a
Key: [5 11] Identity Hash Code:20050612 Object: com.xxx.ServiceAsset@131f2b4
New Objects:
UnitOfWork(21690871)--begin unit of work commit
ServerSession(9727266)--Connection(9256290)--TopLink, version: OracleAS TopLink
- 10g (9.0.4.2) (Build 040311)
ServerSession(9727266)--Connection(9256290)--connecting session: Default
ServerSession(9727266)--Connection(9256290)--connecting(DatabaseLogin(
platform=>Oracle9Platform
user name=> "xxx"
datasource URL=> "jdbc:oracle:thin:@kfir.xxx.com:1521:ORTD"
ClientSession(30940873)--client released
ClientSession(30227927)--client released
ClientSession(26675936)--client released
ServerSession(9727266)--Connection(9256290)--Connected: jdbc:oracle:thin:@kfir.xxxxx.com:1521:ORTD
User: xxxxxx
Database: Oracle Version: Oracle9i Release 9.2.0.1.0 - Production
JServer Release 9.2.0.1.0 - Production
Driver: Oracle JDBC driver Version: 9.2.0.1.0
ClientSession(23126121)--Connection(9256290)--begin transaction
UnitOfWork(21690871)--Execute query WriteObjectQuery(com.xxx.Application@1079ff)
UnitOfWork(21690871)--Execute query WriteObjectQuery(com.xxx.AssetType@152853d)
UnitOfWork(21690871)--Execute query WriteObjectQuery(com.xxx.AssetType@14c7a98)
UnitOfWork(21690871)--Execute query WriteObjectQuery(com.xxx.AssetType@186ed7a)
UnitOfWork(21690871)--Execute query WriteObjectQuery(com.xxx.ServiceProvider@174cb21)
UnitOfWork(21690871)--Execute query WriteObjectQuery(com.xxx.StatusType@151ac10)
UnitOfWork(21690871)--Execute query WriteObjectQuery(com.xxx.Service@e920f)
UnitOfWork(21690871)--Execute query WriteObjectQuery(com.xxx.DomainUrl@180f545)
UnitOfWork(21690871)--Execute query WriteObjectQuery(com.xxx.Domain@44ffb2)
UnitOfWork(21690871)--Execute query WriteObjectQuery(com.xxx.ServiceAsset@131f2b4)
UnitOfWork(21690871)--Execute query WriteObjectQuery(com.xxx.ServiceAsset@26dfcc)
UnitOfWork(21690871)--Execute query WriteObjectQuery(com.xxx.ServiceAsset@14fcd9a)
ClientSession(23126121)--Connection(9256290)--commit transaction
ServerSession(9727266)--Connection(9256290)--disconnect
UnitOfWork(21690871)--end unit of work commit
UnitOfWork(21690871)--release unit of workJames
I have revised the code to show that the ServiceAsset is included in the cache Service object's collection, the Service working copy's collection acquired through the UOW before the remove() call, and still exists after the remove() call. I also show that at all times the ServiceAsset's service is never set to null, by accessing the Service's collection via the ServiceAsset.
What is the remove() method actually doing, if Service specifies serviceAssets as java.util.Collection, serviceAssets get instantiated as new java.util.ArrayList, and MW specifies IndirectList for indirection?
The wierd thing is that the cached Service object's serviceAsset collection actually grows after the remove() is called on the working copy.
Thanks if you can offer any further ideas.
James
public void delete(AssetType assetTypeProto, Service serviceProto) throws PersistenceException {
ServerSession ss = (ServerSession)SessionManager.getManager().getSession("Default");
ClientSession cs = ss.acquireClientSession();
UnitOfWork uow = cs.acquireUnitOfWork();
Service service = (Service)cs.readObject(serviceProto);
for (Iterator it =service.getServiceAssets().iterator(); it.hasNext(); ) {
ServiceAsset sa = (ServiceAsset)it.next();
System.out.println(sa.getService().getServiceId() + " | " + sa.getAssetType().getAssetTypeId());
AssetType assetType = (AssetType)cs.readObject(assetTypeProto);
uow.logMessages();
ServiceAsset serviceAsset = new ServiceAsset();
serviceAsset.setService(service);
serviceAsset.setAssetType(assetType);
serviceAsset = (ServiceAsset)cs.readObject(serviceAsset);
System.out.println("ServiceAsset to delete: serviceId: " + serviceAsset.getService().getServiceId() + " and assetTypeId: " + serviceAsset.getAssetType().getAssetTypeId());
System.out.println("Does ServiceAsset to delete exist in Service collection? " + serviceAsset.getService().getServiceAssets().contains(serviceAsset));
System.out.println("Does ServiceAsset to delete exist in Service collection again? " + service.getServiceAssets().contains(serviceAsset));
ServiceAsset workingCopyServiceAsset = (ServiceAsset)uow.registerExistingObject(serviceAsset);
Service workingCopyService = (Service)uow.registerExistingObject(service);
System.out.println("ServiceAsset Working Copy to delete: serviceId: " + workingCopyServiceAsset.getService().getServiceId() + " and assetTypeId: " + workingCopyServiceAsset.getAssetType().getAssetTypeId());
System.out.println("Does ServiceAsset Working Copy to delete exist in Service Working Copy collection? " + workingCopyServiceAsset.getService().getServiceAssets().contains(workingCopyServiceAsset));
System.out.println("Does ServiceAsset Working Copy to delete exist in Service Working Copy collection again? " + workingCopyService.getServiceAssets().contains(workingCopyServiceAsset));
workingCopyService.getServiceAssets().remove(workingCopyServiceAsset);
System.out.println("Does ServiceAsset Working Copy to delete exist in Service Working Copy collection? " + workingCopyServiceAsset.getService().getServiceAssets().contains(workingCopyServiceAsset));
System.out.println("Does ServiceAsset Working Copy to delete exist in Service Working Copy collection again? " + workingCopyService.getServiceAssets().contains(workingCopyServiceAsset));
uow.commit();
service = (Service)cs.readObject(serviceProto);
for (Iterator it =service.getServiceAssets().iterator(); it.hasNext(); ) {
ServiceAsset sa = (ServiceAsset)it.next();
System.out.println(sa.getService().getServiceId() + " | " + sa.getAssetType().getAssetTypeId());
ServerSession(9089012)--client acquired
ClientSession(11633812)--acquire unit of work: 22482780
ClientSession(11633812)--Execute query ReadObjectQuery(com.xxx.ce
ntral.Service)
11 | 1
11 | 2
11 | 5
ClientSession(11633812)--Execute query ReadObjectQuery(com.xxx.ce
ntral.AssetType)
ClientSession(11633812)--Execute query ReadObjectQuery(com.xxx.ce
ntral.ServiceAsset)
ServiceAsset to delete: serviceId: 11 and assetTypeId: 5
Does ServiceAsset to delete exist in Service collection? true
Does ServiceAsset to delete exist in Service collection again? true
UnitOfWork(22482780)--Register the existing object com.xxx.centra
l.ServiceAsset@773d03
UnitOfWork(22482780)--Register the existing object com.xxx.centra
l.AssetType@da5bc0
UnitOfWork(22482780)--Register the existing object com.xxx.centra
l.Service@6f19d5
UnitOfWork(22482780)--Register the existing object com.xxx.centra
l.ServiceProvider@4a0ac5
UnitOfWork(22482780)--Register the existing object com.xxx.centra
l.Application@12cd8d4
UnitOfWork(22482780)--Register the existing object com.xxx.centra
l.Domain@15da7d
UnitOfWork(22482780)--Register the existing object com.xxx.centra
l.Service@6f19d5
UnitOfWork(22482780)--Register the existing object com.xxx.centra
l.DomainUrl@34f445
UnitOfWork(22482780)--Register the existing object com.xxx.centra
l.Domain@15da7d
UnitOfWork(22482780)--Register the existing object com.xxx.centra
l.StatusType@d8c3ee
UnitOfWork(22482780)--Register the existing object com.xxx.centra
l.Service@6f19d5
ServiceAsset Working Copy to delete: serviceId: 11 and assetTypeId: 5
UnitOfWork(22482780)--Register the existing object com.xxx.centra
l.ServiceAsset@c707c1
UnitOfWork(22482780)--Register the existing object com.xxx.centra
l.AssetType@19ccb73
UnitOfWork(22482780)--Register the existing object com.xxx.centra
l.Service@6f19d5
UnitOfWork(22482780)--Register the existing object com.xxx.centra
l.ServiceAsset@15b6aad
UnitOfWork(22482780)--Register the existing object com.xxx.centra
l.AssetType@12e7cb6
UnitOfWork(22482780)--Register the existing object com.xxx.centra
l.Service@6f19d5
UnitOfWork(22482780)--Register the existing object com.xxx.centra
l.ServiceAsset@773d03
UnitOfWork(22482780)--Register the existing object com.xxx.centra
l.ServiceAsset@1f1e666
Does ServiceAsset Working Copy to delete exist in Service Working Copy collectio
n? true
Does ServiceAsset Working Copy to delete exist in Service Working Copy collectio
n again? true
Does ServiceAsset Working Copy to delete exist in Service Working Copy collectio
n? true
Does ServiceAsset Working Copy to delete exist in Service Working Copy collectio
n again? true
UnitOfWork(22482780)--begin unit of work commit
ServerSession(9089012)--Connection(12832866)--TopLink, version: OracleAS TopLink
- 10g (9.0.4.2) (Build 040311)
ServerSession(9089012)--Connection(12832866)--connecting session: Default
ServerSession(9089012)--Connection(12832866)--connecting(DatabaseLogin(
platform=>Oracle9Platform
user name=> "skynetdev"
datasource URL=> "jdbc:oracle:thin:@kfir.xxx.com:1521:ORTD"
ServerSession(9089012)--Connection(12832866)--Connected: jdbc:oracle:thin:@kfir.
surfkitchen.com:1521:ORTD
User: SKYNETDEV
Database: Oracle Version: Oracle9i Release 9.2.0.1.0 - Production
JServer Release 9.2.0.1.0 - Production
Driver: Oracle JDBC driver Version: 9.2.0.1.0
ClientSession(11633812)--Connection(12832866)--begin transaction
UnitOfWork(22482780)--Execute query WriteObjectQuery(com.xxx.cent
ral.Application@14f5021)
UnitOfWork(22482780)--Execute query WriteObjectQuery(com.xxx.cent
ral.AssetType@fd9b97)
UnitOfWork(22482780)--Execute query WriteObjectQuery(com.xxx.cent
ral.AssetType@f12b72)
UnitOfWork(22482780)--Execute query WriteObjectQuery(com.xxx.cent
ral.AssetType@1bdbf9d)
UnitOfWork(22482780)--Execute query WriteObjectQuery(com.xxx.cent
ral.ServiceProvider@1092447)
UnitOfWork(22482780)--Execute query WriteObjectQuery(com.xxx.cent
ral.StatusType@1277a30)
UnitOfWork(22482780)--Execute query WriteObjectQuery(com.xxx.cent
ral.Service@91520)
UnitOfWork(22482780)--Execute query WriteObjectQuery(com.xxx.cent
ral.DomainUrl@90ed81)
UnitOfWork(22482780)--Execute query WriteObjectQuery(com.xxx.cent
ral.Domain@bb6255)
UnitOfWork(22482780)--Execute query WriteObjectQuery(com.xxx.cent
ral.ServiceAsset@b890dc)
UnitOfWork(22482780)--Execute query WriteObjectQuery(com.xxx.cent
ral.ServiceAsset@46a09b)
UnitOfWork(22482780)--Execute query WriteObjectQuery(com.xxx.cent
ral.ServiceAsset@ce3b62)
ClientSession(11633812)--Connection(12832866)--commit transaction
ServerSession(9089012)--Connection(12832866)--disconnect
UnitOfWork(22482780)--end unit of work commit
UnitOfWork(22482780)--release unit of work
ClientSession(11633812)--Execute query ReadObjectQuery(com.xxx.ce
ntral.Service)
11 | 1
11 | 2
11 | 5
11 | 5
ServerSession(9089012)--client acquired
ClientSession(4496124)--Execute query ReadObjectQuery(com.xxx.cen
tral.Service)
10-Jun-2004 14:59:17 org.apache.struts.util.PropertyMessageResources <init>
INFO: Initializing, config='org.apache.struts.taglib.html.LocalStrings', returnN
ull=true
ClientSession(11633812)--client released
ClientSession(4496124)--client released -
Can I create my own logical unit of work (LUW)?
Good day, everyone!
This is an off-shoot to a Why does the NOCOMMIT parameter not work in HR_INFOTYPE_OPERATION? yesterday in this forum.
It appears that the FM I'm calling is going to do a commit, no matter what. The only thing I can tell is that the NOCOMMIT parameter is used to do a rollback only in the event of a problem.
What I'd like to do is somehow "encapsulate" my call to this function with my own "LUW" designation so that, depending on what a user selects in a selection screen (run as test only? checkbox) I can rollback changes on my own. Unfortunately, I don't know if this is even possible and, if so, how to do it. I need to do something because the end users running this function would like to be able to do a "test run" of all the address transactions to see if there's any errors, data that still needs cleaned up, etc.
Any ideas? Points awarded for all helpful answers, as always.Hai Dave Packard
Go through the following Link
For Logical database
Logical Unit of Work (LUW)
A Logical Unit of Work (LUW or database transaction) is an inseparable sequence of database operations which must be executed either in its entirety or not at all. For the database system, it thus constitutes a unit.
LUWs help to guarantee database integrity. When an LUW has been successfully concluded, the database is once again in a correct state. If, however, an error occurs within an LUW, all database changes made since the beginning of the LUW are canceled and the database is then in the same state as before the LUW started.
An LUW begins
each time you start a transaction
when the database changes of the previous LUW have been confirmed (database commit) or
when the database changes of the previous LUW have been cancelled (database rollback)
An LUW ends
when the database changes have been confirmed (database commit) or
when the database changes have been canceled (database rollback)
Database commit and rollback
Within an LUW, database changes are not made until after a database commit. Prior to this, any database change can be canceled by a database rollback.
In the R/3 System, a database commit is triggered either automatically or by the ABAP/4 command COMMIT WORK or the appropriate Native SQL command for the database system.
Similarly, a database rollback is triggered either automatically or by the ABAP/4 command ROLLBACK WORK or the appropriate Native SQL command for the database system.
A database commit is triggered automatically by
each screen change, and especially after the ABAP/4 commands CALL SCREEN, CALL DIALOG, CALL TRANSACTION, MESSAGE or
a Remote Function Call
A database rollback is triggered automatically by
errors which occur at runtime or
the ABAP/4 command MESSAGE with the message type 'A'
After each database commit or rollback, the database locks set in the LUW are released (see Database Locking).
Thanks & regards
Sreenivasulu P
Message was edited by: Sreenivasulu Ponnadi -
Conform in unit of work broken when not enabling Read Subclasses On Query
Any business application must use conform in unit of work to have expected ACID properties or modifications done during a unit of work are not visible when executing queries.
So our application is always using conform in unit of work. We are using TopLink 10.1.3.3.
We have couple of mapped inheritances. One of them is setup so that when you query on the base class the subclasses are never returned. This is done in TopLink Workbench in inheritance tab by not checking checkbox "Read Subclasses On Query".
The SQL generated is right. But the code handling conform in unit of work doesn't respect the flag.
The code in UnitOfWork.java line 4185 is calling:
getIdentityMapAccessor().getAllFromIdentityMap(expression, class1, databaserow, inmemoryqueryindirectionpolicy);
This end-up to call IdentityMapManager.java line 648:
public IdentityMap getIdentityMap(Descriptor descriptor)
/* 648*/ if(descriptor.hasInheritance())
/* 649*/ descriptor = descriptor.getInheritancePolicy().getRootParentDescriptor();
No places in the code are trying to respect deactivation of "Read Subclasses On Query".
So the query return also subclasses that were in the unit of work!
Anybody else is using conform in unit of work?This is a bug, the subclasses should be getting filtered when conforming.
Please contact Oracle technical support with this issue.
As a workaround you could filter the subclass in your application after executing the query (or possibly use a query redirector), or disable conforming.
<p>---
<br>James Sutherland
<br>Oracle TopLink, EclipseLink
<br>Wiki: Java Persistence, EclipseLink -
Getting Unit Of Work without JSP context
We are developing an application using Toplink and ADF Datacontrols. We have timer (which starts right after deploy) which reads data from magnetic card reader and stores them into database (via Toplink). Our main problem is getting Unit Of Work (server session). If user interacts with application via jsp pages, obtaining uow is done from TopLinkDataControl (getAssociatedUnitOfWork()). But timer lives on its own, it has no jsp pages to get context from.
We know one solution - getting server session from toplink descriptor (absolute path needed) - XMLProjectReader.read("c:\\...\\toplink-deployment-descriptor.xml"). Is there another way to create Unit Of Work for our timer in order to last whole application existence? Thanks.I was wrong, when I thought, that XMLProjectReader.read() with absolute path works. Your solution seems to be similar, with the same result. I'll describe my problem more closely:
- Our web apllication consists of 2 projects - Model and ViewController. Each has set the classpath pointing to classes of the opposite project.
- The only way, that I know of starting a Clock (from Model, Runnable) without creating JSP page is instatiating it in some servlet's init() method. (Servlet has set 'Load This Servlet When the Web App is Strted" in WEB.XML).
- When I try in my clock to create UnitOfWork by XMLProjectReader.read("c:\\...\\toplink-deployment-descriptor.xml"), I get this error:
EXCEPTION [TOPLINK-3007] (OracleAS TopLink - 10g (9.0.4.5) (Build 040930)): oracle.toplink.exceptions.ConversionException
EXCEPTION DESCRIPTION: The Object [mypackage.MyClass], of class[class java.lang.String] could not be converted to [class java.lang.Class]. Please ensure that the class [class java.lang.Class] is on the CLASSPATH. You may need to use alternate
API passing in the appropriate class loader as required, or setting it
on the default ConversionManager/
INTERNAL EXCEPTION: java.lang.ClassNotFoundException: mypackage.MyClass
- mypackage.MyClass is one of many classes from Model, mapped in toplink-deployment-descriptor.xml. It is in classpath of ViewController.
- For the time being, our application runs in JDeveloper, it will be deployed to OracleAS 10g.
Either somebody please help me how to solve above error or maybe suggest how to start my clock together with application deployment (no jsp context).
Thanks. -
I have a toplink descriptor called ToplinkRelationshipInfo which has a one-to-many mapping to a descriptor called ToplinkRelationshipAttribute. The mapping is privately owned and uses a foreign key from ToplinkRelationshipAttribute.info_id -> ToplinkRelationshipInfo.id. The ToplinkRelationshipAttribute has a one-to-one mapping back to the ToplinkRelationshipInfo.
The toplink generated Java source for ToplinkRelationshipInfo has a removeFromAttributes method:
public void removeFromAttributes(ToplinkRelationshipAttribute aToplinkRelationshipAttribute) {
this.attributes.remove(aToplinkRelationshipAttribute);
aToplinkRelationshipAttribute.setRelationshipInfo(null);
}When deleting/removing one of these attributes, if I simply call the above method and then call commit on the unit of work I get a SQLException:
Internal Exception: java.sql.SQLException: ORA-01407: cannot update ("WC"."WP_RELATIONSHIP_INFO_ATT"."RELATIONSHIP_INFO_ID") to NULL
I understand that the reason for this is because the removeFromAttributes method is setting the attribute relationshipInfo member to null, which is causing an UPDATE on the attribute record with null on the required relationshipInfoId.
As suggested in another thread I removed the line that sets the relationshipInfo member to null and I no longer get the exception.
For maintenance reasons I'd prefer to modify as little generated toplink code as necessary, so I'd rather not have to modify the remove method; otherwise I'll have to go through and modify all these types of methods anytime I generate new Java source.
So, how come toplink is generating the code that nulls these member variables if they have to be taken out later?
Is there a way to configure the workbench project so that it does not generate this code, or is it necessary to modify these methods each time I generate the Java source?
Thanks.In a 1-m mapping the relationship is stored in the database by the foreign key of the 1-1 (m-1) back reference. In a typical 1-m relationship if you just remove the object from the collection it will not update the database unless you also set the 1-1 back to null, (as it will still be referencing the old source and the relationship will be out of synch).
In your case because the 1-m is privately owned and the target will be deleted, it does not need to have the 1-1 updated, so you are correct in removing the code.
In have logged an enhancement request internally with the MW to have this code improved for private-owned 1-m relationships.
In general the source code generation of the TopLink Mapping Workbench (or JDeveloper) is meant as a one-time generation for rapid prototyping, it is not required, and not two-way. Typically the object model will be used to provide application specific behavior, so will be maintained by hand after the initial prototype. -
Privately owned object delete problem
If I delete a privately owned object (B), AND delete its parent (object A, contains B), then the order of SQL deletes is incorrect:
DELETE FROM A
DELETE FROM B
If I just delete object A, then Toplink orders deletes properly:
DELETE FROM B
DELETE FROM A
NOW, the question is, can something be done to fix this because not deleting a privately owned object is not an option (its a long story, but there is a business logic related to this that deletes A when no more B's left, but there is no way to know that up front).
Thanks
- rustam -There is a previous thread regarding some similar issues:
Order of delete in unit of work
The last 2 or 3 posts make me wonder if the issue is similar to the one you are experiencing.
Does that thread help? -
Issues updating with Unit of Work
Hello,
I think, I might be missing a point about toplink. I know that when I need to update an Object, i find the current object in cache(ReadObject) and then register that object to get a cloned object and do updates on the cloned object and then commit it.
Everything works fine in above scenario, IF AND ONLY IF, I set the attributes of the cloned object individually. But the update doesn't work if I set the cloned object to a totally different object (clonedObj = otherObj) Here otherObj has changed attributes which i want to be updated. Toplink somehow doesn't like it.
How do i do it?
Sample working code:
public void mergeData(Object obj, Class c){
try{
ReadObjectQuery query = ReadObjectQuery(obj);
// get the object with the primary key as the one passed in
Object persistableObject = session.executeQuery(query);
Object objectClone = tx.register(persistableObject);
//It is a User object
((User)objectClone).setName("New Neeraj");
tx.commit();
Sample NOT working code
public void mergeData(Object obj, Class c){
try{
ReadObjectQuery query = ReadObjectQuery(obj);
// get the object with the primary key as the one passed in
Object persistableObject = session.executeQuery(query);
Object objectClone = tx.register(persistableObject);
objectClone = obj //passed in object
tx.commit();
Is it becuase of the ReadObjectQuery using the same object as used to set up the cloned object?
Thanks in advance for the help.
Regards,
NeerajDon,
This is what the documentation says related to mergeClone:
"Merge the attributes of the clone into the unit of work copy. This can be used for objects that are returned from the client through RMI serialization (or another serialization mechanism), because the RMI object will be a clone this will merge its attributes correctly to preserve object identity within the unit of work and record its changes. The object and its private owned parts are merged."
What is the significance RMI and serialization in this.
I tries mergeClone locally (using the UOW) and it works fine, but just want to make sure that I understand what the documentation says.
Also, if you will be kind enough to explain the difference between mergeClone and mergeCloneWithReferences.
Thanks,
Neeraj -
Insertion using objects and update using queries in a single unit of work
HI All,
I have a set of objects that i want to insert and then perform some update queries ( direct queries ) on the inserted data in the same transaction. but when i register the objects and execute the update SQL's on the same data in a same unit of work, the update statements are executed first and then the inserts are happening, I've also tried with child unit of work and parent unit of work but the result is the same.
Can any one suggest a way to do object insertion and sql updates in a single transaction, Thanks in advance
Regards,
Sai KrishnaThe UnitOfWork is an abstraction for the physical database query. By default nothing is actually written into the database until the UnitOfWork commits. This means making updates to new objects involves modifying them in-memory and then the updated values will be included in the INSERT during commit.
If you are having difficulty finding the newly created objects you can enable the query conforming capabilities to have modified and new objects included in query comparisons without requiring them to first be written to the database.
Doug -
Order of delete in unit of work
Hi,
I'm trying to delete two objects, a beamprocess and a beamprocessType, where the beamprocess has a 1-1 relationship with the beamprocessType. This means of course that the beamprocess must be deleted before the beamprocessType. I illustrate this with a method below, but a short explanation is probably required.
A sequence holds cycles, which holds beamprocesses. These are 1-M private relationships so these objects are all deleted when the sequence is deleted. For some of the beamprocesses I also want to delete the associated beamprocessType. My problem is that when I call commit on the unit of work, TopLink tries to delete the beamprocessType before the associated beamprocess, which is not possible. How can I solve this?
Kind regards,
Katarina
The method:
public void deleteSequence(String name) throws PMException {
SequenceController sequenceController = (SequenceController) ServiceLocator.getInstance().getService(SequenceController.class);
Sequence sequence = sequenceController.getSequence(NameFactory.createSequenceName(name));
PersistenceTransaction tx = PersistenceLayerFactory.getPersistenceLayer().acquireTransaction();
// Delete all the "beam-out" beamprocess types and settings.
Cycle[] cycles = sequence.getCycles();
for (int i = 0; i < sequence.getCycles().length; i++) {
BeamProcess[] bps = cycles.getBeamProcesses();
for (int j = 0; j < bps.length; j++) {
BeamProcess bp = bps[j];
if (bp.isBeamOut())
tx.deleteObject(bp.getType());
tx.deleteObject(sequence);
tx.commit();Hi again,
I have now tried to modify my descriptor by adding the contstraint afterwards, but with no success:
java.util.Map descriptors = project.getDescriptors();
Descriptor descriptor = (Descriptor) descriptors.get(BeamProcessImpl.class);
descriptor.addConstraintDependencies(BeamProcessTypeImpl.class);As mentioned in the previous posting, we do not use any mappings that are not specified in the mapping workbench, so TopLink should be able to order them properly. I include below the mapping descriptor for the BeamProcess class, with the hope that this will give you additional information to be able to help me solve this "mystery". I also include the error message.
Kind regards,
Katarina
Descriptor:
<descriptor>
<java-class>cern.macsy.core.domainimpl.BeamProcessImpl</java-class>
<tables>
<table>CORE_BEAMPROCESS</table>
</tables>
<primary-key-fields>
<field>CORE_BEAMPROCESS.OID</field>
</primary-key-fields>
<descriptor-type-value>Normal</descriptor-type-value>
<sequence-number-field>CORE_BEAMPROCESS.OID</sequence-number-field>
<sequence-number-name>BP_SEQ</sequence-number-name>
<identity-map-class>oracle.toplink.internal.identitymaps.SoftCacheWeakIdentityMap</identity-map-class>
<remote-identity-map-class>oracle.toplink.internal.identitymaps.SoftCacheWeakIdentityMap</remote-identity-map-class>
<identity-map-size>100</identity-map-size>
<remote-identity-map-size>100</remote-identity-map-size>
<should-always-refresh-cache>false</should-always-refresh-cache>
<should-always-refresh-cache-on-remote>false</should-always-refresh-cache-on-remote>
<should-only-refresh-cache-if-newer-version>false</should-only-refresh-cache-if-newer-version>
<should-disable-cache-hits>false</should-disable-cache-hits>
<should-disable-cache-hits-on-remote>false</should-disable-cache-hits-on-remote>
<alias>BeamProcessImpl</alias>
<copy-policy>
<descriptor-copy-policy>
<type>oracle.toplink.internal.descriptors.CopyPolicy</type>
</descriptor-copy-policy>
</copy-policy>
<instantiation-policy>
<descriptor-instantiation-policy>
<type>oracle.toplink.internal.descriptors.InstantiationPolicy</type>
</descriptor-instantiation-policy>
</instantiation-policy>
<query-manager>
<descriptor-query-manager>
<existence-check>Check cache</existence-check>
</descriptor-query-manager>
</query-manager>
<event-manager>
<descriptor-event-manager emptyAggregate="true">
</descriptor-event-manager>
</event-manager>
<mappings>
<-snipp->
<database-mapping>
<attribute-name>oid</attribute-name>
<read-only>false</read-only>
<field-name>CORE_BEAMPROCESS.OID</field-name>
<type>oracle.toplink.mappings.DirectToFieldMapping</type>
</database-mapping>
<-snipp->
<database-mapping>
<attribute-name>type</attribute-name>
<read-only>false</read-only>
<reference-class>cern.macsy.core.domainimpl.BeamProcessTypeImpl</reference-class>
<is-private-owned>false</is-private-owned>
<uses-batch-reading>false</uses-batch-reading>
<indirection-policy>
<mapping-indirection-policy>
<type>oracle.toplink.internal.indirection.NoIndirectionPolicy</type>
</mapping-indirection-policy>
</indirection-policy>
<uses-joining>false</uses-joining>
<foreign-key-fields>
<field>CORE_BEAMPROCESS.BEAMPROCESS_TYPE</field>
</foreign-key-fields>
<source-to-target-key-field-associations>
<association>
<association-key>CORE_BEAMPROCESS.BEAMPROCESS_TYPE</association-key>
<association-value>CORE_BEAMPROCESSTYPE.OID</association-value>
</association>
</source-to-target-key-field-associations>
<type>oracle.toplink.mappings.OneToOneMapping</type>
</database-mapping>
</mappings>
<type>oracle.toplink.publicinterface.Descriptor</type>
</descriptor>Error message:
[EXCEPTION [TOPLINK-4002] (TopLink - 9.0.3 (Build 423)): oracle.toplink.exceptions.DatabaseException
EXCEPTION DESCRIPTION: java.sql.SQLException: ORA-02292: integrity constraint (MACSYDEV.BEAMPROCESS_BPTYPE) violated - child record found
INTERNAL EXCEPTION: java.sql.SQLException: ORA-02292: integrity constraint (MACSYDEV.BEAMPROCESS_BPTYPE) violated - child record found
ERROR CODE: 2292] -
I have counted a problem to remove a private owned object from database. The object is removed from toplink cache successfully but the database row still exists.
OfferResult object contains multiple OfferDailyResult objects.
The attribute in OfferResult:
mktgElementTkey: String (primary key)
offerDailyResults: ArrayList
The attributes in OfferDailyResult:
mktgElementTkey: String (primary key)
resultDate: Timestamp (primary key)
resultValue: String
I am able to remove any OfferDailyResult object from offerDailyResults collection in application server. But the database row is still sitting in Offer_Daily_Result table.
Is that because I have a Timestamp attribute in the primary key? How can I solve it?
I'm using weblogic 9.2 and toplink 10.1.3. Since our application was migrated from lower version toplink to toplink 10.1.3, the old way to turn on sql log doesn't work. Could you also tell me how to turn on the sql log?
Thanks,Here is the peseudo-code of removing OfferDailyResult
object. I have trouble to turn on the Toplink SQL log
in version 10.1.3. Could you tell me how to turn on
it?
public class OfferResult extends MktgElement {
String mktgElementTkey;
ArrayList lnk_TelemktgOfferDailyResult;
public void removeDailyResult(String
resultDateStr) {
TelemktgOfferDailyResult dailyResult =
this.getTelemktgOfferDailyResult(resultDateStr);
dailyResult.getResultDate().setNanos(0);
this.lnk_TelemktgOfferDailyResult.remove(this.getTele
ktgOfferDailyResult(resultDateStr));
Thanks,This code doesnt show how you are registering the object and then deleting it. Can you include the transaction code as well-the part where you acquire a unit of work, register the object you want to delete as well ? -
Privately Owned and Cascade Delete in DB
HI,
What is the relationship between setting privately owned in Toplink vs creating a cascade delete in Oracle DB? If I've the cascade delete in DB then what is the advantage of setting the privately owned flag in toplink?
ThanksIf you only set the cascade delete option in the database, then TopLink will have no knowledge that the private object was deleted (or that it is private in general). This would mean that TopLink would not remove the private object from the cache or process it as have being deleted. In general this may not cause your app any direct issues if you never read the private object directly as it will eventually garbage collect from the cache.
Making the relationship privately own in TopLink will also ensure the following:
- If you replace the private object with another, or set it to null, TopLink will delete the old object on the update of the source. Cascade delete only works on deletion.
- If the relationship is a 1-m and you remove an object from the collection it will be removed.
- If you refresh the parent object, by default the child will also be refreshed.
- If you merge the parent object, by default the child will also be merged. -
Deploying iworks suite when ipad will become privately owned in future
I have a mix of privately owned and school owned ipads that are supervised by my MDM.
The school owned ipads will become privately owned ipads in several years.
As part of the supervision users can't install their own apps, can not remove apps.
They can sign into iTunes.
Apps are deployed from the MDM.
Is there a way I can deploy iworks using tokens to the school owned ipads which will still allow the ipads to have iworks installed by the owners of the ipads when they are no longer school owned. To clarify, I want users in several years time when the MDM no longer has control of the ipads to be able to install iworks, but until then I want to control the installation.
With the privately owned ipads can I send deploy iworks but allow the users to activate the account using there own iTunes accounts?
Is this also the way forward for the school owned ipads.@To the OP:
I own a X-Fi Elite Pro for the past 8 years now.
Since there, this card has faithfullly seen me through 3 major PC upgrades.
I'm currently at a point where, very sadly, much of what you've described is also weighing on my decision to not go for a Z line.
@Creative:
I do hope you're listening and can come up with a solution to a simply design feature - namely a fully working Stereo Surround, like the one that was available in the X-Fi line of cards via CMSS-3D.
Regards, -
Rule Execution : Error while executing a rule session unit of work
Error while executing a rule session unit of work.
The rule session CreditRule:130002 failed to execute a unit of work.
Check the underlying exception and correct the error. Contact oracle support if error is not fixable.
I have created a simple rule and using a decision service and a decide process activity I have tried to run the orchestration.
After compiling and saving and re-opening the orchestration flow looks correct.
When I execute the process I get the above error.
Is this something wrong with the Rule ?
Can anyone offer any advice
Thanks
CliffHi.
Any further advice on this issue?
Getting the same problem and cannot figure out a solution.
How do I check the "underlying exception" btw?
Maybe you are looking for
-
Hello Friends, My client is facing a problem while creating a service entry sheet for a PO. In the PO history it is showing a service entry sheet(SES) is created for a line item. But that SES has been revoked and deleted also. But the concern is alth
-
Java API for working with Pivot Tables...?
Hi, I want to create/modify an existing pivot table in an excel sheet. Is there any open source available to work on pivot tables. I have seen few articles mentioning that POI supports updation of data, though the apache site says that it does not su
-
I have been on for days trying to set my mms up on the Nokia lumia 10 . I have just been on the o2websight because I had tryed everything else I have put in the iPhone settings and its now sending pictures why hasn't any other setting worked
-
Reservation in Material Document
Hi all, I am facing with and issue related to Reservation. Problem Defination. In the Material document List for a particualar MAterial i am able to see the Reservation no. i.e a material has been issued against a reservation so material document is
-
How to open PDF in Form6i and send it to printer
I am still using very old version of developer which is developer 6i. I would like to know how to do the following two things: 1. open a set of PDF files (which are stored in DB as BLOB) in Form6i 2. print them all out by a single button click in For