Conforming UnitOfWork New Object w/assignSequenceNumber
If I:
1. Create an instance of a mapped object.
2. Assign the appropriate values.
3. Call UnitOfWork.registerNewObject();
4. Call assignSequenceNumbers();
5. And, using the same UnitOfWork but before committing to the database, create a ReadObjectQuery with an Expression to search on the newly-assigned Sequence Number.
Then, is it possible for a ReadObjectQuery to find this value?
I have tried:
1. On the descriptor, setting setShouldAlwaysConformResultsInUnitOfWork(true);
2. On the query, checkCacheByPrimaryKey();
Nothing works.
Everything in the docs suggests I should be able to do this, but I always get null. Is there any way to get this newly registered object out of the UnitOfWork?
Nate,
Here is a chunk of code I just wrote to perform what I believe you want. I use regsiterObject instead of registerNewObject and I set conforming on the query.
UnitOfWork uow = getSession().acquireUnitOfWork();
Employee newEmp = new Employee(); // Original
Employee wcEmp = (Employee) uow.registerObject(newEmp); // Register and recieved working copy
uow.assignSequenceNumbers();
System.out.println("Original id: " + newEmp.getId() + " - " + newEmp.hashCode());
System.out.println("WC id: " + wcEmp.getId() + " - " + wcEmp.hashCode());
// Now we'll search for it
ReadObjectQuery roq = new ReadObjectQuery(Employee.class);
roq.setSelectionCriteria(roq.getExpressionBuilder().get("id").equal(wcEmp.getId()));
roq.conformResultsInUnitOfWork();
Employee emp = (Employee) uow.executeQuery(roq);
System.out.println("Found: " + emp.getId() + " - " + emp.hashCode());
The output from the run gives me:
Original id: 0 - 33459432
WC id: 471 - 29345020
Found: 471 - 29345020
As you can see the working copy returned from the register is the one that has the PK assigned and is also returned from the query.
Doug
Similar Messages
-
Design and registration of new objects
We have the following three objects:
- Order, which contains:
-- OrderStatus
-- Vector: OrderStatusHistoryItem
Whenever order.setStatus(newStatus) is called we would like to create a new OrderStatusHistoryItem and add that to the vector of history inside the Order.
Our first guess was to put this in the setStatus method of the Order object, so that noone would bypass the adding to history. But... When creating the OrderStatusHistoryItem inside the Order we of course get an error from TopLink, saying that the object was not registered in the UOW.
Is there some way that we can tell TopLink that this relationship should be registered automatically on commit? If not, what would be the best way to design this? Of course we do not want to expose our domain layer to the internals of TopLink. Would a factory be the best way to handle registration upon creation?
Thanks,
Anders,Anders,
New objects created and attached to working copies will be discovered during commit cycle and added to the persistent model including the appropriate INSERT. The only issue you will have is that you must make sure that setStatus(newStatus) is ONLY called on working copies read from or registered with a UnitOfWork. If this is true you should be able to create the new OrderStatusHistoryItem within the setStatus method and add it to the collection without registering it in the UnitOfWork.
Doug -
RegisterObjet (for a new object) return a clone form a different object
Hello,
when I register a new object with registerObject method, I sometimes receive an object from the same class but a clone from an other objet.
How is that possible ?
thanks
AnnabelleHello Annabelle,
When you call registerObject(someObject), TopLink will perform an existence check to see if the object passed in is new or existing, then return a working copy of the object passed in. It the object was previously registered, it will pass the same working copy back, otherwise, it will clone the object passed in to use as the working copy.
Are you using sequencing?
If registerObject is passing back the same working copy for multiple new objects, there might be a problem with the object's primary key - which is used for identity.
Try printing off what is in the identity maps using the session.getIdentityMapAccessor().initializeIdentityMaps() api on the UnitOfWork. This should show all the objects in the cache as well as the primary keys they are cached under, which might help to identify the problem object and how it got in the cache.
Best Regards,
Chris -
How to add a new object to Toplink session cache?
Toplink Experts,
I have a question on Toplink 9.0.4.5 (I know this is older version of Toplink but this is what we are using right now). Let me give you little context before I ask the question.
Toplink server session brokers client sessions (that are spawned by it) and gets changes made in client sessions into server session through transaction commits. Process involved in getting some thing into database using Toplink is: 1) Get client session 2) Register object to be written into database with Toplink's UnitOfWork (UOW). This registration creates two copies of the object registered (original object). Working clone for client application for modifications, backup clone for Toplink to compare the changes made to the working clone later 4) Make changes to the working clone 5) Complete the transaction (and so commit UOW). If transaction commits successfully, Toplink writes the changes from the working clone into database first and applies the same changes made to the working clone to the original object in Toplink server session cache next. Oracle recommends using UOW to write some thing into database. Using UOW involves a transaction and it writes changes into database first before the original object in Toplink server session cache is refreshed.
Now comes my question: Is there a way to add a brand new object (persistent object) into Toplink server session cache with out writing it first into database? I am OK if I need to use UOW and also to use transaction to make the change but I just want to be able to refresh the original object in the server session cache with out writing any thing into database. If there is a way to do this? What are the disadvantages in doing this way though? I have read Oracle's Toplink developer guide (10.1.3) and Javadocs from Oracle on UnitOfWork/Session etc all related interfaces and classes but I could not find a way. Please help!
SyamThere are a couple things wrong with the method you posted. The first being uow.registerObject() is going to cause the object to be treated as new if you are not using the TopLink cache.
There really is not any supported mechanism to do what you are looking to do. TopLink 11g has the hooks to replace the TopLink cache with a distributed cache (and the TopLink-Grid product uses these to use Coherence as the TopLink cache) but earlier versions did not have this.
If you are willing to work outside what would be officially supported and no component of the application is using the ServerSession cache (ie all queries refresh) then something like the following may work for you:
public void prepareObjectForSave(Object userEditedObject, Object gigaSpacesObject)
UnitOfWork unitOfWork = this.dbContext.getSession().acquireUnitOfWork();
Descriptor descriptor = this.dbContext.getSession().getDescriptor(gigaSpacesObject);
Object pkVector = descriptor.getObjectBuilder().extractPrimaryKeyFromObject(gigaSpacesObject, this.dbContext.getSession());
Object cloneOfMostRecentlyUpdatedObject = (Object)unitOfWork.cloneAndRegisterObject(gigaSpacesObject, new CacheKey(pKVector), descriptor);
unitOfWork.mergeCloneWithReferences(userEditedObject);
unitOfWork.commit();
}You will need to tweak the above code to have it match the APIs in your version of TopLink and you should test thoroughly.
--Gordon -
TopLink does not generate SQL statements for inserting new objects
TopLink does not generate SQL statements for inserting new objects. Why?
Thanks in advance...Please see the response in
Why does not unitofwork.commit write data to the database?
Regards,
Chris -
Doubt in creation of a new object
Hi All,
I have one doubt in creation of a new object.If a new object is to be created and it is not a subtype
of any existing object, then what should we enter in the Program field for creating the object?
I hope I am clear with my question.
Thanks in Advance,
Saket.Hi Saket,
Following will be required for created a custom business object.
1. Object Type - ZTEST (Internal Techincal Key)
2. Object Name - ZTESTNAME (Technical Key Name)
3. Name - TEST (Name of BO, it is used while selecting the object type)
4. Description - (Short Description of BO)
5. Program - ZTESTPROGRAM (ABAP program in which the methods of the object type are implemented)
6. Application - A or B.. etc (Area to which your BO is related)
Please remember that you can learn these basic things by giving F1 help on those fields and in HELP.SAP.COM.
Regards,
Gautham Paspala -
What is the diffrence between extends and creating new object?
HI ALL,
what is the diffrence between extends and creating new object?
meaning
class base{
class derived extends base{
class base{
class derived {
derived(){
base var = new base();
can u people tell me diffence from the above examples.
THANKS.
ANANDAWhen you create a new object you have to supply the class to which that
object belongs. A class can extend from another class. If it does so
explicitly you can define the 'parent' class from which the class extends.
If you don't explicitly mention anything, the class will implicitly extend
from the absolute base class named 'Object'.
Your example is a bit convoluted: when you create a Derived object,
its constructor creates another object, i.e. an object from the class from
which the Derived class extends.
Extending from a class and creating an object don't have much in common.
kind regards,
Jos -
Creating a new object at runtime
What I want to do is dynamically change the name of a object
everytime I create a new one, what I mean excatly is like make it
so that I can some how increment a value of a variable and apply it
to an object anme... so I get something like this
objectName0, objectName1, objectName2, objectName3 and so on.
I basically want to make it so that I always have a new object to
use... how would I go about doing this?You don't need exec, the api provides this functionality for you. Look at the java.util.jar package.
-
It will not parse! Creating a new object in the universe
Hi, we have a universe and BO reports. They work fine for our clients. We are on BO XI r3.1. Now, one client captures an additional piece of info. They would like to report against this and add it high up on our drilling heirarchy. "Sure, no problem". For the following I was logged in as administrator.
The additional data field is a 3 character code.
1) We added an additional column to the actual database table.
2) In Universe Designer, I refreshed universe structure and could see the additional column
3) Created an object 'Acode' that refers to db.new_field
4) Exported universe
Maybe worth mentioning that I can see this object and use it in reports fine in Infoview.
Now, I need to create a new object that will be one of 2 strings based on the 3 character code (Acode) i.e. the 'Atype' can be X or Y.
Here's my code and it just will not parse:
CASE
WHEN @Select(AFolder\Acode) = 'CEL'
THEN 'X'
ELSE u2018Yu2019
END
Error I get is:
Parse failed:Eception:DBD ODBC SQL Server driverStatement could not be prepared.State 42000
I'd appreciate any help, believe me I have searched the forums!
Thanks, EddieLook at following SAP NOtes.
1373739
1184304
Regards,
Bashir Awan -
Setting the name of a new object from a string
Is there anyway I can set the object name of a newly created
object from a string?
eg.
(the code below generates a compile time error on the
variable declaration)
public function addText(newTxt:String, txt:String,
format:TextFormat):void {
var
this[newTxt]:TextField = new TextField();
this[newTxt].autoSize = TextFieldAutoSize.LEFT;
this[newTxt].background = true;
this[newTxt].border = true;
this[newTxt].defaultTextFormat = format;
this[newTxt].text = txt;
addChild(this[newTxt]);
called using>
addText("mytxt", "test text", format);
I could then reference the object later on without using
array notation using mytxt.border = false; for example
There are many a time when I want to set the name of a new
object from a string.
In this example I have a function that adds a new text object
to a sprite.
The problem is, if I call the function more than once then
two textfield objects will exist, both with the same name. (either
that or the old one will be overwritten).
I need a way of setting the name of the textfield object from
a string.
using
var this[newTxt]:TextField = new TextField()
does not work, If I take the "var" keyword away it thinks it
a property of the class not an object.
resulting in >
ReferenceError: Error #1056: Cannot create property newTxt on
Box.
There must be a way somehow to declare a variable that has
the name that it will take represented in a string.
Any help would be most welcome
ThanksUsing:
var this[newTxt]:TextField = new TextField()
is the right approach.
You can either incrment an instance variable so that the name
is unique:
newTxt = "MyName" + _globalCounter;
var this[newTxt]:TextField = new TextField();
globalCounter ++;
Or store the references in an array:
_globalArray.push(new TextField());
Tracy -
Getting ORA-20001: Creation of new object is not allowed: !!
Hi Am getting ORA-20001: Creation of new object is not allowed while enabling constraints after importing the dumps from source to target datbase,can anyone assist me to fix this issue.
Hi Osama/Mustafa,Thanks for your quick response,can you please explain me the following things-
1)As i don't have privilege to run the DBA_XX views,am not able to run those queries-
SELECT OWNER, TRIGGER_NAME, TRIGGER_BODY FROM DBA_TRIGGERS WHERE TRIGGER_TYPE IN ('AFTER EVENT', 'BEFORE EVETN') AND TRIGGERING_EVENT LIKE '%CREATE%';
can you tell me what output it'll throw,based on this output how will we fix the issue.
2)SELECT * FROM dba_sys_privs WHERE privilege = 'UNLIMITED TABLESPACE';
why we need to check this privilege?as i don't have privilege to run this one in my db.
3)select * from dba_source where upper(text) like upper('%Creation of new object is not allowed%');
as i don't have privilege to run this one in my db,already i got the object name from my logfile
and more you have quoted"This is an error of someone that coded purposely on your database, probably dba or a developer who has privilege and again it is in a database event trigger"
4)can you explain me much more deeper about the root cause and as already sent note to my DBA,can you explain me the solution to fix this issue ? -
Creation of new object link for DMS
i have searched a lot about Creation of new object link for DMS on internet .
and all replies focus on that documentation :
1. Program two screens for the following module pools for the SAP object that is to be linked additionally:
u2013 SAPLCV00
u2013 SAPLCVIN
The process logic must be according to that of screen 0204 in program SAPLCV00 and must not be changed.
2. Create the function module OBJECT_CHECK_XXXX (XXXX = name of the SAP object).
i need to know how to implement that in more detailed step by step
as i know DMS and abap also.Hi Reda,
Hope the below URL will help to understand how the Process of adding a object link works.
Enhancement Without Modification of the Object Links - Engineering Change Management (LO-ECH) - SAP Library
Thanks & Regards,
Seshadri. -
Schema of a new Object Type: message pass the BIU without validation
Hi,
i've defined a new Object Type for send messages to Web Service. I've created the schema files and i've uploaded there in repository with the "Import" function of GUI. After, i've defined the XML file for the "Execute" function of the B1i GUI.
After the load of files, in the repository the files are in correct position.
In my BIU the definition of sender and receiver system type is correct, and also the definition of SenderMainObjectTypeID and ReceiverObjectTypeID. The message from B1 pass through the IPO chain without problems and the message is received by teh Web Service.
If modify the file XSL into the BIU, a message with less elements than a schema pass without problem.
If delete the schema from repository, the message pass without validation.
I would know because the schema is bypassed...
ThansOk,
solved with introduction of validation point in a customized IPO using a branch / unbranch atoms.
Bye. -
Hi Sir/Madam,
Currently we are implementing DMS(Document Management System) and
our main requirement is to add document to the delivery and billing
document.In t-code dc10 in "define object link" lips and vbrp object is
not present in the default list so how we can add these new object in
order to attach new document to delivery as well as billing document.
Is it possible to attach document at header level because we have to
attach lorry number at delivery header which will be common for all the
items.
The function module object_check_lips already exist in se37 but we
have to create new function module for object vbrp.How to create this
function module? How we have to create screens for these objects? If we
have to create it by copying some function module like
object_check_equithan what will be the funtion group.
IN delivery document (vl03n) in menu bar in "extras" document
option is not there than how we will see the attached document, do we
have to create this option with help of abaper or this option will
automatically reflect after all the cofiguration?
Thanks and Regards
Abhilash NayakHi Abhilash,
You need to gofor z-development for this. The Abap'r will add the new required object in object link field. Also the DMS screen will appear in the required t-code.
Meantime you need to add this object in SPRO , "maintain key fields".
I hope this will resolve the query.
Regards,
Ravindra -
New-object itextsharp causes an error
Hi, i am trying to use powershell to read a pdf document with the following code
[System.Reflection.Assembly]::LoadFrom(".\itextsharp.dll")
$reader = New-Object iTextSharp.text.pdf.PdfReader -ArgumentList ".\201408_issue.pdf"
for ($page = 1; $page -le $reader.NumberOfPages; $page++) {
$lines = [char[]]$reader.GetPageContent($page) -join "" -split "`n"
foreach ($line in $lines) {
if ($line -match 'test')
$matches[1]
I get an error though, has anyone encoutnered this? Thanks
New-Object : Exception calling ".ctor" with "1" argument(s): "Object reference not set to an instance
of an object."
At C:\PsScripts\test\PDFReader\PDFReader.ps1:2 char:11
+ $reader = New-Object iTextSharp.text.pdf.PdfReader -ArgumentList ".\201408_RIN_i ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [New-Object], MethodInvocationException
+ FullyQualifiedErrorId : ConstructorInvokedThrowException,Microsoft.PowerShell.Commands.NewObject
CommandPS C:\PsScripts\test\PDFReader> $error[0].Exception | Format-List * -Force
ErrorRecord : Exception calling ".ctor" with "1" argument(s): "Object reference not
set to an instance of an object."
StackTrace : at System.Management.Automation.DotNetAdapter.AuxiliaryConstructorInvo
ke(MethodInformation methodInformation, Object[] arguments, Object[]
originalArguments)
at
System.Management.Automation.DotNetAdapter.ConstructorInvokeDotNet(Type
type, ConstructorInfo[] constructors, Object[] arguments)
at
Microsoft.PowerShell.Commands.NewObjectCommand.CallConstructor(Type
type, ConstructorInfo[] constructors, Object[] args)
WasThrownFromThrowStatement : False
Message : Exception calling ".ctor" with "1" argument(s): "Object reference not
set to an instance of an object."
Data : {}
InnerException : System.NullReferenceException: Object reference not set to an instance
of an object.
at iTextSharp.text.pdf.PdfReader.ReadObjStm(PRStream stream,
IntHashtable map)
at iTextSharp.text.pdf.PdfReader.ReadDocObj()
at iTextSharp.text.pdf.PdfReader.ReadPdf()
TargetSite : System.Object AuxiliaryConstructorInvoke(System.Management.Automation.Met
hodInformation, System.Object[], System.Object[])
HelpLink :
Source : System.Management.Automation
HResult : -2146233087
Any meaning to you?
Maybe you are looking for
-
I having trouble installing device driver ref. cd's on windows XP 64 bit OS
I recently purchased labVIEW 8.2.1 and the sound and vibration toolkit. The DAQ unit I have is the ni-9233USB. I 've got a couple of options as far as computers that I can load the software onto. The computer that I would like to use is my laptop,
-
How to use customer_update_sales_area
Hi Friendz Could anybody tell me How I would use this function module to upload partner function. I can find documentation for this. Warm regards Manisha
-
Project Server 2013 - Workflow Execution " Submit button is grayed out. "
Dear All, As i was in progress to making workflows in sharepoint designer this is my first project of implementing project server 2013 and executing the workflows,in the continuation of this i followed below mentioned link to go through the process o
-
HT203175 Problems upgrading iTunes on Windows XP - Help needed...
trying to upgrade my iTunes on a Windows XP won't work - it claims that my downloaded upgrade file is on an unavailable disk. Same thing happens if I try to uninstall the old version. Any suggestions?
-
Backup of Sun ONE Directory Server 5.2
Hello, I am new to Sun ONE Directory server and I installed a copy of version 5.2 on Windows 2000 server and want to ask for your help that how could I backup the LDAP server? Since there is tool for backup of data but how could I recover if the serv