I am using one oracle db with two copies of same application one is uploaded to server and one through local host through remote connection.problem is in primary key constraint on inserting entries in db table by both application.Suppose there is 5 entries in db table with last entry having primary key value 5,currently both the applications having last value 5 in session,now suppose one application inserts a new row it will increment primary key to 6 and inserts it successfully now if second application wants to insert a row in same table it will try to insert with primary key 6 because in its session last value was 5,but in the db there is already a row with primary key 6(inserted by first app) there it gives Unique constraint exception.
can anyone suggest how to take current value of primary key from DB not from session...??? Thanks in Advance..
Related
I have a table which needs to be ingested from Oracle source to Greenland target using ETL tool talend. The table is huge , hence we want to load the data on daily basis incrementally. The table doesn't have any primary or unique key.
Table has date column, I am able to get both inserted/updated records from last update date but to insert that data, we need a primary key.
Any solution on how to load the data without using a primary key?
You need to define your key in talend in the schema of the component that insert into your target table, like this :
And you can use this key to update your table, in the advanced settings of the same component, activate the check box use fields optins and select your key :
This is tested and worked fine against Oracle table that does not have primary key, and it should work for you.
i have taken target table as my lookup table using static cache.in source i have duplicate values.
in mapping i ahve used update strategy transformation but not i m not able update data in target table
Example:Initially(i mean after session Load)
source table Lookup table Target table
ID Name ID Name ID Name
1 A 1 A 1 A
2 B 2 B
Now im inserting two more records
3 C
1 E
but its not updating below record
1 E
i am getting below error
One or more values in the INSERT statement, UPDATE statement, or foreign key update caused by a DELETE statement are not valid because the primary key, unique constraint or unique index identified by "1" constrains table "TABLE_NAME" from having duplicate values for the index key.
I know if i use dynamic lookup it will work correctly but in static.
please give the reason ASAP.
There is a requirement in our application to create the unique primary key which depend on the value of another unique column (ERROR_CODE). But our application is in a geo active active environment (have several active databases which are synchronized using another program).
Therefore even-though we have a unique constraint on this ERROR_CODE field, there is a possibility that each database has a row with a different PK for the same ERROR_CODE. During the database synchronization, this is a problem, because there are some child tables which has the PK stored in one DB and other rows contain the PK stored in other DB. Because of the unique constraint of ERROR_CODE, sync process cannot move both rows to each database (which is also not a good thing to do).
So there is a suggestion to use the hash of the ERROR_CODE field as the PK value.
I would like to know whether we can define a function based Primary key in oracle?
If PK field is "ID",
"ID" should be equal to ora_has(ERROR_CODE).
Is it possible to define the primary key like that in oracle?
In Oracle 10 you cannot do this, but in Oracle 11 you can. You have to create a virtual column, such columns can be used also as primary key:
ALTER TABLE MY_TABLE ADD (ID NUMBER GENERATED ALWAYS AS (ora_has(ERROR_CODE)) VIRTUAL);
ALTER TABLE MY_TABLE ADD CONSTRAINT t_test_pk PRIMARY KEY (ID) USING INDEX;
i would like to generate java classes using hibernate (Netbeans).
This seems not to be possible when the tables do not have a primary key.
I have no access to the database, i just found out, that they used sequences instead of primary keys.
create sequence SEQ_ANY
minvalue 0
maxvalue 99999999999999999999
start with 0
increment by 1000
cache 20;
So my Question is now, can i edit hibernate.hbm or hibernate.cfg.xml or any other file to tell hibernate which class contains a primary key?
f.e.
<table name="myTable">
<useThisFieldAsPrimaryKey name="uniqueSequenz"/>
</table>
Thank you!
A sequence is an objects to provide you with unique values for a primary may. Thus your table probably has a primary key which consists of a single column.
Then every table has a primary key (in the worst case all columns together form the primary key - which normally would be a bad database design). A primary key can have more than one column.
Hibernate likes primary keys which are made of a single column. Nevertheless you can define composite keys made of more than one column in Hibernate.
You need the schema of your table. If not you are stuck.
i have table. which has 5 columns in that 3 of the columns makes primary key combinations.
table (cola, colb, colc, cold, cole)
i want to update one of the column which is in primary key group. how to do that?
its giving primary key constraint error.
You should disable do your modification an re enable the constraints that are linked to your primary key. (Unique, non-null, etc...)
Take a look at this website
If you really need to maintain uniqueness over these three columns, then define a unique constraint on the three columns making up your current PK, and then define a new surrogate primary key column.
Just in case you have to change the referncing data too.
First note contrary to MS-SQL-Server there is no foreign Key contraint with on update cascade see How to create a Foreign Key with “ON UPDATE CASCADE” on Oracle?.
Than I would insert a new row in the primary table, update the referencing table to reference the new row and finally delete the original primary row.