Arcehtype Validation
Submitted by Ben_Charlton on Thu, 26/03/2015 - 17:12
Hi Guys (well Tim)
I am creating a few test to work through functions I want to test with my export patch
Party customer = (Party) create(ExportArchetypes.CUSTOMER); Party importer = (Party) create(ExportArchetypes.IMPORTER); bean.addParticipation(ExportArchetypes.EXPORTER_PARTICIPATION,customer); bean.addParticipation(ExportArchetypes.IMPORTER_PARTICIPATION,importer); IMObjectBean customerbean = new IMObjectBean(customer); IMObjectBean importerbean = new IMObjectBean(importer); Lookup mr = TestHelper.getLookup("lookup.personTitle", "MR"); customerbean.setValue("title", mr.getCode()); customerbean.setValue("firstName", "Foo"); customerbean.setValue("lastName", "Bar"); customerbean.save(); Lookup mrs = TestHelper.getLookup("lookup.personTitle", "MRS"); importerbean.setValue("title", mrs.getCode()); importerbean.setValue("firstName", "Jane"); importerbean.setValue("lastName", "Doe"); importerbean.save(); bean.save();
that final line throws an error. The exporter is just a party.customer and the importer is a modified party.customer (no patient nodes)
The exporter participation is a participation.customer and the import participation is a
org.openvpms.component.business.dao.im.common.IMObjectDAOException: Object not found: party.importer:-1:61bffb41-d37a-11e4-b31d-c3dcc4e3ece2
at org.openvpms.component.business.dao.hibernate.im.IMObjectDAOHibernate.saveDeferred(IMObjectDAOHibernate.java:949)
at org.openvpms.component.business.dao.hibernate.im.IMObjectDAOHibernate.preCommit(IMObjectDAOHibernate.java:527)
at org.openvpms.component.business.dao.hibernate.im.common.Context$ContextSynchronization.beforeCommit(Context.java:530)
at org.springframework.transaction.support.TransactionSynchronizationUtils.triggerBeforeCommit(TransactionSynchronizationUtils.java:95)
at org.springframework.transaction.support.AbstractPlatformTransactionManager.triggerBeforeCommit(AbstractPlatformTransactionManager.java:927)
at org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:737)
at org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:723)
at org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:147)
at org.openvpms.component.business.service.archetype.rule.ArchetypeRuleService.execute(ArchetypeRuleService.java:171)
at org.openvpms.component.business.service.archetype.rule.ArchetypeRuleService.save(ArchetypeRuleService.java:115)
at org.openvpms.component.business.service.archetype.DelegatingArchetypeService.save(DelegatingArchetypeService.java:208)
at org.openvpms.component.business.service.archetype.helper.IMObjectBean.save(IMObjectBean.java:1643)
at org.openvpms.archetype.rules.export.ExportRulesTestCase.testGetFullName(ExportRulesTestCase.java:55)
I initially thought it was because I was derefencing the importer object when i created the bean reference, but running bean.save() prior to declaring the customer and importerbeans gives the same error.
Re: Arcehtype Validation
Try adding the participation references after you've saved the customer and importer. The way you've done it will only work if you save everything in the one transaction.
Re: Arcehtype Validation
When I changed to using the Testhelper.createCustomer() method this worked fine.
So I have my tests working , but I still dont understand why when I the importer and exporter objectrefs seem to be dereferenced from the underlying objects when I try and save the export act bean.
So this test passes and I am still saving the customerbean after I have added the participation...and I never need to call bean.save();
I suspect I may be missing a basic understanding of object dereferencing here from "Java 101" and if so just tell me to go read a textbox on Java objects...
I dislike not having a complete grasp as to why one method works when another fails.
Re: Arcehtype Validation
To uniquely identify IMObject instances, OpenVPMS uses:
When you save an object for the first time, its id is updated with the actual database id. Until that time, its linkId is used to identify it.
If you reference an unsaved object outside of a transaction, the ArchetypeService has no way of saving that reference in the database, as it needs a valid id.
Within a transaction, the ArchetypeService can use the linkId to resolve the appropriate IMObject. So if you have multiple unsaved objects that reference each other, you can either:
When you used the customer returned by TestHelper.createCustomer(), it had already been saved, thus had a valid database id.