Toplink insert sequence
Hi all:
Is there any sequence in which toplink fires insert/update queries to the database if there is no object mapping..?
Actually I have domain classes which have mapping using the primaryKeys but not the actual objects.
I am using toplink 9037.
Regards,
Viral
TopLink will not insert or update objects that have no descriptor or mappings.
If more information is required perhaps you could explain, with examples, what your object model looks like and what, exactly, it is that you are attempting to do.
--Gordon
Similar Messages
-
Inserting sequence value from JDBC and getting the same value back
Hi: Gurus I have a table whose primary key is a sequence. I wonder how to make sure I get the same sequence value back for current transaction so I update the other table whose foreign key is the sequence value from first table.
E.g lets say I do this
String query_insert = INSERT INTO table1 (column1, ....) VALUES (HIGHLIGHT_ID_SEQ.nextval, ...);
pstmt = con.prepareStatement(query_insert);
pstmt.executeUpdate();
How I make sure no other transaction update the sequence value so I can read the last inserted sequence value and update the second table with this value
String query_select = "SELECT HIGHLIGHT_ID_SEQ.currval FROM DUAL";
pstmt = con.prepareStatement(query_select);
Regards,
Rashid.<rant>No version again. I wonder why people requiring help want to stay anonymous and never want to type their version, only 4 digits. In this case, jdbc, not only the version of the driver is important, but also it's type. Waving a magic wand again? </rant>
Look up the returning into clause of the insert statement in the sql reference manual for your version.
Sybrand Bakker
Senior Oracle DBA -
Inserting sequence value in a created column already table having some rows
i have a table emp whish has already having rows in that table
now i added one more column to that table with alter command and also i created sequence
now i want to insert the value in that newly created column with sequencename.nextval??????insert into employees values (employees_seq.nextval);
commit;
Here employees_seq is the name of the sequence.
Regards
Asif Kabir
17 (17 unresolved)
-- Mark your answer as correct/helpful
Edited by: asifkabirdba on Dec 22, 2009 3:39 PM -
Creating/Inserting sequence. V 1.6
Hi, I have a Create Record page with a hidden ' :P2_ERROR_NUMBER ' item. I would like this number to increase sequentially every time a new record is created and added to my 'METADATACOPY' table. Right now there are around 70 records in the table with the first ten records having error numbers 1-10 in order.<br><br>Can I create a sequence that will begin at error number 11 when I view the 11th record and submit it to the table for an update, increment by 1, with last number 10?<br><br>
Right now I have:<br>
Name METADATACOPY_ERRNUM_SEQ <br>
Min Value 1 <br>
Max Value 999999999999999999999999999 <br>
Increment By 1 <br>
Cycle Flag N <br>
Order Flag N <br>
Cache Size 20 <br>
Last Number 10 <br><br>
Would the next step be to create a process on page 2 such as:<br>
Name:Error_Number,
PointOnload - before header?<br><br>
If I create this as a process do I need to create a trigger?Hi Leo,
I am not 100 % I understand what you are asking. :-) Why dont you just assign an ERROR_NUMBER to the 70 rows you have manually. Then alter the sequence so it starts with the 71.
To get the ERROR_NUMBER to increase automatic make a database trigger something like this:
create or replace metadatacopy_b_ins_r
after insert on metadatacopy
for each row
begin
if :new.error_number id null then
select metadatacopy_errnum_seq.nextval
into :new.error_number
from dual
end if;
end;
This is what I normally do. But you can also do it in the application with an on submit after computations and validations process with source like this:
declare
function get_pk return varchar2
is
begin
for c1 in (select metadatacopy_errnum_seq.nextval next_val
from dual)
loop
return c1.next_val;
end loop;
end;
begin
:P2_ERROR_NUMBER := get_pk;
end;
The process should be linked to the CREATE button via the conditional processing in the process.
Hope this helps. -
TopLink inserts when it should update, unique constraint exception
The title says most of it. I am creating a series of objects and then updating them in rapid succession. It would be great to handle all the values during the insert, but it's not possible for this process. The majority of the time, the cached object is updated correctly and no problem occurs, but every once in a while TopLink tries to re-insert the previously inserted object, instead of updating it. Obviously this throws a unique constraint exception for the PK, and boots me out of the process.
I can refreshObject and then it works fine. I'm looking for the underlying cause though. I want to be able to use the cache!
Thanks!!
Aaron
Oracle JDBC driver Version: 10.2.0.3.0
Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bit Production
TopLink Release-Designation: 10g Release 3Hello,
How are you obtaining these objects to update them? The likely cause is that you are running out of memory and the objects in the shared identity map are getting garbage collected due to weak references. This means that when they get registered, TopLink can't find them in the cache so assumes they are new (the default existence check is check cache).
If this is the case, there are a few options.
1) Increase the size of the cache for the class in question to something more appropriate for your application, or use a fullIdentyMap so nothing ever gets pushed out. Of course, a FullIdentityMap should not be used lightly as it prevents its objects from beign gc'd and has consequences to related objects as described in:
Caching Causing Memory Leak Effect
Both these options will require more memory resources though, so if garbage collection is running and clearing out the references because you are already low on memory, this might make GC need to run more frequently
2) Increase the JVM memory. This assumes completely that GC is clearing out the unused weak references from your cache because it is low on memory - GC can still occur so it doesn't guarantee the problem will be any better
3) Read in the object through the UnitofWork before making changes (instead of using RegisterObject on existing objects), use the registerExistingObject for known existing objects or use the uow mergeClone method. Merge should cause the object to be read from the database if it is not in the cache, but it depends on the existence options used
Best Regards,
Chris -
Hi,
From my ADF Page I am calling the TopLink Query to update a record if it exists else insert a new record. I have an issue where first time if the record doesn't exist a new record is inserted in the Database table, next time if another call is made the record is updated. Now if I go and delete a Record in the Table and again Run the Query from my ADF Page the record is never inserted as it should insert a Record because I manaully deleted the Record before running the query again. Any idea what might be wrong looks like something is cached and when the query runs again it never creates the record. If I don't delete a record and manually update the data and run the query again it still doesn't update the record. Looks like only first time it works i.e. inserts a record and then updates it but after that any requests never do anything in the table. As it should update or insert a record for each request coming from ADF Page. Here is the code I have:
Session session = getSessionFactory().acquireSession() ;
UnitOfWork uow = session.acquireUnitOfWork() ;
ExpressionBuilder builder = new ExpressionBuilder() ;
Expression expression = builder.get("stateName").equal("TX").and(builder.get("deptDesc").equal("HR")).and(builder.get("id").equal("1234")).and(builder.get("user").equal("XASW")).and(builder.get("mngCont").equal("3A45")) ;
DepartmentDescription dd = (DepartmentDescription)uow.readObject(DepartmentDescription.class,
expression) ;
if (dd == null)
dd = new DepartmentDescription() ;
dd.setStateName("TX") ;
dd.setId("1234") ;
dd.setDeptDesc("HR") ;
dd.setUser("XASW") ;
dd.setMngCont("3A45") ;
dd.setValue("Record Inserted") ;
else
dd.setValue("Record Updated") ;
uow.registerObject(dd) ;
uow.commit() ;
session.release();
ThanksThis is because the object is still in the TopLink cache.
<p>
You can either invalidate the object in the TopLink cache (session.getIdentityMapAccessor().invalidateObject()), or use registerNewObject to force the insert. If it is just a test, you could also clear the cache (session.getIdentityMapAccessor().initializeIdentityMaps()), ).
<p>
You could also disable the cache by setting your descriptor to be isolated.
<p>
-- James : EclipseLink -
Automatically insert sequence call by defined subsequences
Good morning,
is it possible, with TestStand 2012, to create a sequence call (automatically) in MainSequence for each defined SubSequence in the same sequence-file?
I have many (as more as 120) tests which are applied as a SubSequence. these Subsequences get called from MainSequence. Now I have to set for every SubSequence a sequence call, this take much time.
My idea is to write a script or a helper sequence which do this job for me, is this possible?
thanks
HeikoYou can use this statement instead...(slightly different than the previous one...and more readable according to me)
RunState.SequenceFile.Data.Seq[Locals.index].InsertStep(RunState.Sequence.GetStep(0, StepGroup_Setup), 0, StepGroup_Main)
A few explanations :
> Locals.index : local variable to index each subsequence in your sequence file
> InsertStep : method to insert the step you specify into the subsequence (with options in order to specify where you want to insert the step in your subsequence : group, and position in the group)
> GetStep : method to get a reference to the step you need to insert in the subsequence (with options in order to specify which step of your main sequence you want to get a reference to : group, and position in the group) -
Toplink insert new value issues
Hi all,
I'm working on toplink and encounter a problem.
I have 3 tables, A(a.id), B(b.id) and relation table AB(a.id(fk),b.id(fk)),
Now table B have one value(b1)(b1 got from sessionBean.findByid method ),
I want to add a new value A(a1) to database, and the relation table AB(a1,b1)
So I have the following code.
A a = new A();
List listAB= new ArrayList();
AB ab = new AB();
ab.SetB(b1);
listAB.add(ab);
a.setAB(ab);
sessionBean.persisA(A)
But the toplink persis B(b1) once again.
So there is an error,because b1 already exists in Database.
Anyone have solution for this problem.
Thanks.The problem is in what sessionBean.persisA(a) does, and what the sessionBean.findByid does - is it just a register object? Also, you describe the A->B table relationship as a Many to Many using an AB as the relation table, but in the objects you seem to create an AB object for the relation table. Is there a reason A just isn't using a collection of Bs with a ManyToManyMapping specifying AB as the relation table? In the code description, you also state a.setAB(ab); which I assume was just a mistake and that the problem really uses a.setAB(listAB), but just to be sure, what do the ab.setB() and a.setAB() methods do, and how is the AB->A value set?
Best Regards,
Chris -
Very Urgent: Insert sequenced and not repeated values in Column
Hello all:
I want help for this, I have master block called orders and details block from it called payments. payments block is a tabular block , I want that when user insert new record in orders and go to insert payments then the (payments.payment_no) column generate automatically as 1 ,2,3,4,5,…… values and this values must be unique for this record in orders block.
Thanks.have look at Re: How to auto generate (auto-increment) Sr Number in the detailed sectio
and How to auto generate (auto-increment) Sr Number in the detailed section? -
Problem with "Insert" and "Overwrite Sequence Content"
I'm working with XDCAM footage. I like to take all the individual clips recorded on the XDCAM disc, and after getting them into FCP, taking them and putting them all in a sequence in FCP, then using that sequence as the source in the Viewer. This allows for quick scanning of all the clips, much as is it were a digitized tape.
I recently found the "Insert Sequence Content" and "Overwrite Sequence Content" commands in FCP, and like them in that they actually put the individual clips into my project timeline, and not just the combined sequence (which looks more or less like a nest when dropped into my project sequence).
Here's the problem: When I put IN and OUT points in the timeline, and "Insert or Overwrite Sequence Content" using the sequence containing all the clips, the video tends to be contained to between the IN and OUT points I set in the TIMELINE, but the audio tracks tend to expand past the OUT point I set in the TIMELINE, and I can't figure out why, or how to get around this.
Any assistance would be appreciated.If you're inserting or overwriting, you're basically pasting the content that you've chosen. I wouldn't think the out point would be recognized, or even wanted. If you copied 5 minutes of clips and inserted it into a sequence with a 4 minute in/out point duration, do you want to only have the first 4 minutes inserted into the sequence? If you only place an in point, it will insert all the clips, starting at that point, and it will take up as much time as the clip content's duration.
Am I missing something here? -
How to return the newly generated sequence id for an INSERT statement
A record is to be inserted into a table with a sequence for the primary key. The newly inserted sequence value is to returned on successful insertion. Is it possible to do all this in a single statement (say executeUpdate or any other) using java.sql.* ?
E.g.: - A student record is to be inserted into the STUDENT table. There is a sequence (by name Student_ID_SEQ) on the primary key Student_ID. Student_ID_SEQ.nextval will generate the new sequence id which will be provided as input to the SQL statement (say statement.executeUpdate) along with other student attribute values. On insertion the created sequence id should be returned. And all this should happen in a single statement (single call to database). Stored Procedures can accomplish this. But is this feasible without the use of Stored Procedures?
Thanks.a better aproach is to generate the auto key on the
database side, not on the application side.That's his problem - since the database is supplying the key for the new record his application which executed the SQL has no way to identify the record that was just added. I just create the key on the app server and accept the likelihood of overlap (which is extremely small).
Here is a more technical explanation:
Table Person
ID,
Name,
Phone Number,
Age
}The field ID is an autonumber, and all other fields are not unique.
Now, when this code executes:
PreparedStatement pst = conn.prepareStatement("Insert Into Person (Name, Phone Number, Age) Values ?, ?, ?");
pst.setString(1, "John");
pst.setString(2, "405-444-5555");
pst.setInt(3, 44);
pst.executeUpdate();How can the app determine the ID of the person just added since no query is possible which is guaranteed to select just the record that was inserted?
Since I am generally against Stored Procedures I would develop a way to insure that your keys were unique and generate them inside the app server. -
How to create a sequence using Toplink for DUAL table
Hi All,
How do I create below sequence using TOPLINK
CREATE sequence my_seq start WITH 1;
Regards,
DheerajHi Dheeraj,
Sequence Object should be created in Database and specify the type of sequence that will be used in toplink to create sequence value.For example,sequence objects created in database needs to be configured using Native Sequence.
For more information refer to the below link.Use JDeveloper Toplink Wizards for declarative programming of Toplink native Sequencing.
http://www.oracle.com/technology/products/ias/toplink/doc/1013/main/_html/reldscfg003.htm.
Regards,
P.Vinay Kumar -
Sequences in toplink-Urgent!
Hi,
I have a Database table which has a column whose value is to be automatically generated from a sequence called 'SEQ_PERSON_ID'.I gave the sequence name,table and id in the workbench but i am getting an error
internal Exception: java.sql.SQLException: ORA-00942: table or view does not exi
st
Error Code: 942
Call:UPDATE SEQUENCE SET SEQ_COUNT = SEQ_COUNT + 50 WHERE SEQ_NAME = 'SEQ_PERSON
_ID'
Please suggest as this is very urgent.Hi i have included both code and project descriptor.
Please suggest.
CODE
public class test
ServerSession aSession = null;
public void login() {
// Get the session from session.xml
aSession = (ServerSession)SessionManager.getManager().getSession("TestSession");
System.out.println(aSession);
* This method is used to disconnect from the database
public void logout() {
aSession.logout();
* Main method
public static void main(String[] args) {
test t = new test();
t.login();
UnitOfWork uow = t.getUnitofWork();
Person p = new Person();
Person clonetest = (Person)uow.registerObject(p);
clonetest.setPersonid(31979);
clonetest.setFirstname("vasubabu");
clonetest.setLastname("bathina");
clonetest.setGender("M");
clonetest.setLastupdatedby("ABC");
clonetest.setLastupdatedwhen(new java.util.Date());
uow.commit();
public UnitOfWork getUnitofWork() {
return aSession.acquireUnitOfWork() ;
Project xml
<?xml version = '1.0' encoding = 'UTF-8'?>
<toplink:object-persistence xmlns:opm="http://xmlns.oracle.com/ias/xsds/opm" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:toplink="http://xmlns.oracle.com/ias/xsds/toplink" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<opm:name>Test</opm:name>
<opm:class-mapping-descriptors>
<opm:class-mapping-descriptor xsi:type="toplink:relational-class-mapping-descriptor">
<opm:class>Person</opm:class>
<opm:alias>Person</opm:alias>
<opm:primary-key>
<opm:field table="PERSON" name="PERSON_ID" xsi:type="opm:column"/>
</opm:primary-key>
<opm:events/>
<opm:querying/>
<opm:attribute-mappings>
<opm:attribute-mapping xsi:type="toplink:direct-mapping">
<opm:attribute-name>firstname</opm:attribute-name>
<opm:get-method>getFirstname</opm:get-method>
<opm:set-method>setFirstname</opm:set-method>
<opm:field table="PERSON" name="FIRST_NAME" xsi:type="opm:column"/>
</opm:attribute-mapping>
<opm:attribute-mapping xsi:type="toplink:direct-mapping">
<opm:attribute-name>gender</opm:attribute-name>
<opm:get-method>getGender</opm:get-method>
<opm:set-method>setGender</opm:set-method>
<opm:field table="PERSON" name="GENDER" xsi:type="opm:column"/>
</opm:attribute-mapping>
<opm:attribute-mapping xsi:type="toplink:direct-mapping">
<opm:attribute-name>lastname</opm:attribute-name>
<opm:get-method>getLastname</opm:get-method>
<opm:set-method>setLastname</opm:set-method>
<opm:field table="PERSON" name="LAST_NAME" xsi:type="opm:column"/>
</opm:attribute-mapping>
<opm:attribute-mapping xsi:type="toplink:direct-mapping">
<opm:attribute-name>lastupdatedby</opm:attribute-name>
<opm:get-method>getLastupdatedby</opm:get-method>
<opm:set-method>setLastupdatedby</opm:set-method>
<opm:field table="PERSON" name="LAST_UPDATED_BY" xsi:type="opm:column"/>
</opm:attribute-mapping>
<opm:attribute-mapping xsi:type="toplink:direct-mapping">
<opm:attribute-name>lastupdatedwhen</opm:attribute-name>
<opm:get-method>getLastupdatedwhen</opm:get-method>
<opm:set-method>setLastupdatedwhen</opm:set-method>
<opm:field table="PERSON" name="LAST_UPDATED_WHEN" xsi:type="opm:column"/>
</opm:attribute-mapping>
<opm:attribute-mapping xsi:type="toplink:direct-mapping">
<opm:attribute-name>personid</opm:attribute-name>
<opm:get-method>getPersonid</opm:get-method>
<opm:set-method>setPersonid</opm:set-method>
<opm:field table="PERSON" name="PERSON_ID" xsi:type="opm:column"/>
</opm:attribute-mapping>
</opm:attribute-mappings>
<toplink:descriptor-type>independent</toplink:descriptor-type>
<toplink:sequencing>
<toplink:sequence-name>seq_person_id</toplink:sequence-name>
<toplink:sequence-field table="PERSON" name="PERSON_ID" xsi:type="opm:column"/>
</toplink:sequencing>
<toplink:instantiation/>
<toplink:copying/>
<toplink:tables>
<toplink:table name="PERSON"/>
</toplink:tables>
</opm:class-mapping-descriptor>
</opm:class-mapping-descriptors>
<toplink:login xsi:type="database-login">
<toplink:platform-class>oracle.toplink.internal.databaseaccess.OraclePlatform</toplink:platform-class>
<toplink:user-name>citytime</toplink:user-name>
<toplink:password>9469F498BD56203FD481D5B2C4201C78</toplink:password>
<toplink:driver-class>oracle.jdbc.driver.OracleDriver</toplink:driver-class>
<toplink:connection-url>jdbc:oracle:thin:@derby:1524:ctfdeva1</toplink:connection-url>
<toplink:native-sequencing>true</toplink:native-sequencing>
</toplink:login>
</toplink:object-persistence> -
Inserting oracle sequence values
hI
Do i need to do a select sequence.nextval from dual
before i insert the next sequence value into the table
For eg i tried using the foll insert statement but i get an invalid number exception
insert into parts(PARTS'DATABASE.PARTNOSEQ.NEXTVAL',"+PARTNO+")
But i get the above exception.I dont do a select now.
Thanks
ArnHi
I tried doing the following trying to insert sequence values but I still get an invalid get Column error.
sql4 = "select PART_SEQ.NEXTVAL FROM DUAL";
ResultSet rs3 = stmt2.executeQuery(sql4);
while (rs3.next())
seqVal = rs.getInt("PART_SEQ");
rs3.close();
for(int i=0; i<=count; i++)
{ // for loop
sql3 = "Update part " +
" SET part_mfr = '"+mfgcodeStr+"' ,
" part_id = "+seqVal+"," +
" WHERE invoiceno = '"+invoicenoStr+"' ";
Thanks
arn -
Sequencing problem with Batch Writing
I'm using TopLink - 9.0.3.5 and I want to use the registerAllObjects method from the UnitOfWork instead of registering each individually to batch write records to the db. Here is a snippet of what I'm doing:
Session session = ToplinkUtils.getSession();
session.getLogin().useBatchWriting();
session.getLogin().dontUseJDBCBatchWriting();
session.getLogin().setSequencePreallocationSize(200);
session.getLogin().setMaxBatchWritingSize(200);
session.getLogin().bindAllParameters();
session.getLogin().cacheAllStatements();
session.getLogin().useNativeSequencing();
UnitOfWork uow = ToplinkUtils.getActiveUnitOfWork(userId, ip);
for loop{
Notification dao = (Notification)
ToplinkUtils.createObject (Notification.class.getName());
dao.setName("someName");
dao.setAddress("someAddress");
allObjects.add(dao);
uow.registerAllObjects(allObjects);
This is the error I'm getting:
2007-03-06 15:28:40,482 DEBUG (11776:9:127.0.0.1) TOPLINK - JTS#beforeCompletion()
2007-03-06 15:28:40,482 DEBUG (11776:9:127.0.0.1) TOPLINK - SELECT GMS_NOTIFICATION_SEQ.NEXTVAL FROM DUAL
2007-03-06 15:28:40,497 DEBUG (11776:9:127.0.0.1) TOPLINK - INSERT INTO GMS_NOTIFICATION ...
2007-03-06 15:28:40,716 DEBUG (11776:9:127.0.0.1) TOPLINK - EXCEPTION [TOPLINK-4002] (TopLink - 9.0.3.5 (Build 436)): oracle.toplink.exceptions.DatabaseException
EXCEPTION DESCRIPTION: java.sql.SQLException: ORA-00001: unique constraint (GMSG2K.GMS_NOTIFICATION_PK) violated
It appears that the next sequence number is aquired for the primary key and a record is added but when Toplink tries to add the next record either the sequence is not aquired or the same sequence number is being used.
Do I need to set up a table in memory to acquire the sequences? Can anyone give me some guidence?
thanksregisterAllObjects() does not do anything special it just calls registerObject(), it does not affect batching.
In 9.0.3 batch writing was not supported with parameter binding, so this is why you are not seeing batching. This support was added in 9.0.4.
In 9.0.4 you should use,
Session session = ToplinkUtils.getSession();
session.getLogin().useBatchWriting();
session.getLogin().setSequencePreallocationSize(200);
session.getLogin().setMaxBatchWritingSize(200);
session.getLogin().bindAllParameters();
session.getLogin().cacheAllStatements();
session.getLogin().useNativeSequencing();
where setMaxBatchWritingSize(200) means 200 statements.
In 9.0.3 you can only use dynamic batch writing, which may not perform well. For dynamic batch writing, setMaxBatchWritingSize(200) means 200 characters (the size of the SQL buffer) so is too small, the default is 32,000.
If you are concerned about performance enabling sequence preallocation would also be beneficial.
If you still get timeouts, you may consider splitting your inserts into smaller batches (100 per each unit of work) instead of all in a single transaction.
Maybe you are looking for
-
BW,cProjects Reports are not working
Hi Gurus, we are using EP7 EHP 2 for PPM 5.0. We have activate all BW contents In BW system but when we click on any report link on report tab in PPM portal system ,it is just showing default web template but when we run the same report from BW syst
-
FlashBuilder deleting folders a bug or a feature that you can turn off???
In my project I have a directory called uploads, when I compile flashBuilder is either deleting the folder, or simply not adding it as part of the project. So when I run my app, it has problems because the directory isn't there. 1. How do I tell Flas
-
ANyone have a good link or tutorial of words in 3d perspective for ps
I want to make a 3d word in perspective view. So that the closest point to the user is large and gets smaller. I tried a couple of tutorials from Google search but cannot get pass the text transform part because all the buttons are greyed out and I c
-
Preview doesn't launch when I double-click a previewed photo in finder
Just noticed today that when I preview a photo in the finder by clicking on the spacebar, I'm unable to double click it so that it launches in the Preview application. I don't remember fiddling with anything before this, and it was okay several weeks
-
How to check a decimal value is negative or not.
Hi, Iam having a value 25000.00- in a variable called sum1. which is a negative value. i want to check whether it is a negative value or not. i tried like if sum1 LT 0. statement. else. statement. but this is not working, can anyone help me in this.