Capture the unique constraint by Apex error?
Hello guys!My application is almost over and I'm currently focusing on the error handling! So far, I was able to solve many problems using the Apexlib.
However, I would like to get rid of these annoying Ora - error messages are not comprehensible to the end user. Is it possible to intercept errors of unique constraint by their Summit before submitting data? If so, could you please be so kind and give me a good or better yet a full example how manage these errors with PL/SQL, or Javascript.
I'm just a beginner so please be a little more detailed, so I can understand your code. :-)
I know your opinion on this question and hope you can help me!
Thank you very much!
Kind regards
Sebastian
Hello Sebastian,.
There is a mistake in your second loop. Must be something Island:
amountx :=0; -- reset the counter
FOR c IN (SELECT count(*) counter FROM tbl_schichtigkeit -- No INTO in this part
WHERE int_schichtigkeit = APEX_APPLICATION.G_F03(j)
AND lng_inv_pt_id = :P52_PTIDS
)
LOOP
amountx := c.counter; --
If amountx > 0 then
RETURN 'Error on row ' || j;
ELSE RETURN NULL;
END IF;
END LOOP;
I'm not sure if you need this loop. I think you can also do it with only:
SELECT count(*) counter
INTO amountx
FROM tbl_schichtigkeit
WHERE int_schichtigkeit = APEX_APPLICATION.G_F03(j)
AND lng_inv_pt_id = :P52_PTIDS;
If amountx > 0 then
RETURN 'Error on row ' || j;
ELSE RETURN NULL;
END IF;
Be aware that it only reports the first error! If there are more records with an error, you won't get one, because you RETURN right after the first found.
Greetings,
Roel
http://roelhartman.blogspot.com/
Tags: Database
Similar Questions
-
Get the "unique constraint" error while mapping custom jsp
Hello
We are implementing iStore R12 (12.1.3).
We have customized ibeCCtdMenu.jsp, renamed as xxibeCCtdMenu.jsp and moved to $OA_HTML / folder.
Now in the template Manager, we create a new source (xxibeCCtdMenu.jsp) file to the title of "model of generation of Menu".
However when we select site and language like 'All', it gives following error:
Error in the logical record of physical mapping
ORA-00001: unique constraint (IBE. IBE_DSP_LGL_PHYS_MAP_U2) violated in the package IBE_PhysicalMap_GRP procedure save_physicalmap
All the sites and all the language already exists exists for 7670 deliverable
How can we overcome them this error? Please notify.
Thank you
Vivekfor a given Site and the language combination, can exist only one model.
Default file provided by Oracle is set with combination like all Sites - all languages, and you will not be able to change it.Save your file with combination such as all Sites - English
or, all languages. Then it will work fine.
Hrishikesh
-
Question of the unique constraint with finance charge
Hi friends,
As part of the implementation of 11 g BIAPPS-ODI during the execution of a finance charge is my load of CM plan failed with the error like below
ODI-1519: series step 'Load start Plan (InternalID:1242500)' failed because step 'Refresh Global Variable (InternalID:1243500)' child is in error.
ODI-1519: series step 'Refresh Global Variable (InternalID:1243500)' failed because the step child "Warehouse loading Phase (InternalID:2336500)" is a mistake.
ODI-1519: series step "Warehouse loading Phase (InternalID:2336500)" failed because the child step "SIL 1 charge (InternalID:2337500)" is a mistake.
ODI-1519: series step '1 SIL Load (InternalID:2337500)' failed, because the child step '2 group of dimensions of SIL (InternalID:2338500)' is a mistake.
ODI-1519: series step '2 group of dimensions of SIL (InternalID:2338500)' failed because the child step "Parallels - independent DimGroup (InternalID:2346500)" is a mistake.
ODI-1518: parallel step 'Parallels - independent DimGroup (InternalID:2346500)' failed. level of 1 child by mistake, which is more than the maximum number of allowed errors (0) defined for parallel step. Has no measures of the child: 3 SIL Dims POSHIER_DIM (InternalID:2369500)
ODI-1519: series step '3 SIL Dims POSHIER_DIM (InternalID:2369500)' failed because the child "POSHIER_DIM (InternalID:2372500)" is a mistake.
ODI-1519: series step "POSHIER_DIM (InternalID:2372500)" failed because step "SIL_PositionDimensionHierarchy (InternalID:2377500)" child is in error.
ODI-1217: SILOS_SIL_POSITIONDIMENSIONHIERARCHY Session (4278500) fails with return code 1.
ODI-1226: SIL_PositionDimensionHierarchy.W_POSITION_DH step fails after 1 attempt.
ODI-1240: Flow Run SIL_PositionDimensionHierarchy.W_POSITION_DH fails during an operation of integration. This flow of charge table target W_POSITION_DH.
ODI-1228: SIL_PositionDimensionHierarchy.W_POSITION_DH (integration) of the task fails when connecting ORACLE target BIAPPS_DW.
Caused by: java.sql.SQLIntegrityConstraintViolationException: ORA-00001: unique constraint (DEV_DW. W_POSITION_DH_U2) violated
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:462)
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:405)
at oracle.jdbc.driver.T4C8Oall.processError(T4C8Oall.java:931)
at oracle.jdbc.driver.T4CTTIfun.receive(T4CTTIfun.java:481)
at oracle.jdbc.driver.T4CTTIfun.doRPC(T4CTTIfun.java:205)
at oracle.jdbc.driver.T4C8Oall.doOALL(T4C8Oall.java:548)
at oracle.jdbc.driver.T4CPreparedStatement.doOall8(T4CPreparedStatement.java:217)
at oracle.jdbc.driver.T4CPreparedStatement.executeForRows(T4CPreparedStatement.java:1115)
at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1488)
at oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java:3769)
at oracle.jdbc.driver.OraclePreparedStatement.execute(OraclePreparedStatement.java:3954)
at oracle.jdbc.driver.OraclePreparedStatementWrapper.execute(OraclePreparedStatementWrapper.java:1539)
at oracle.odi.runtime.agent.execution.sql.SQLCommand.execute(SQLCommand.java:163)
at oracle.odi.runtime.agent.execution.sql.SQLExecutor.execute(SQLExecutor.java:102)
at oracle.odi.runtime.agent.execution.sql.SQLExecutor.execute(SQLExecutor.java:1)
at oracle.odi.runtime.agent.execution.TaskExecutionHandler.handleTask(TaskExecutionHandler.java:50)
at com.sunopsis.dwg.dbobj.SnpSessTaskSql.processTask(SnpSessTaskSql.java:2913)
at com.sunopsis.dwg.dbobj.SnpSessTaskSql.treatTask(SnpSessTaskSql.java:2625)
at com.sunopsis.dwg.dbobj.SnpSessStep.treatAttachedTasks(SnpSessStep.java:577)
at com.sunopsis.dwg.dbobj.SnpSessStep.treatSessStep(SnpSessStep.java:468)
at com.sunopsis.dwg.dbobj.SnpSession.treatSession(SnpSession.java:2093)
at com.sunopsis.dwg.dbobj.SnpSession.treatSession(SnpSession.java:1895)
to oracle.odi.runtime.agent.processor.impl.StartScenRequestProcessor$ 2.doAction(StartScenRequestProcessor.java:580)
at oracle.odi.core.persistence.dwgobject.DwgObjectTemplate.execute(DwgObjectTemplate.java:216)
at oracle.odi.runtime.agent.processor.impl.StartScenRequestProcessor.doProcessStartScenTask(StartScenRequestProcessor.java:512)
to oracle.odi.runtime.agent.processor.impl.StartScenRequestProcessor$ StartScenTask.doExecute (StartScenRequestProcessor.java:1068)
at oracle.odi.runtime.agent.processor.task.AgentTask.execute(AgentTask.java:137)
to oracle.odi.runtime.agent.support.DefaultAgentTaskExecutor$ 2.run(DefaultAgentTaskExecutor.java:82)
at java.lang.Thread.run(Thread.java:662)
How to solve the question above using ODI 11 g. I'm using Oracle ERP R12.1.3 as a source of data for this.
Thanks in advance.
Kind regards
Saro
What is the result of a query on table W_POSITION_DH or W_POSITION_D duplicate?
Naeem
-
DBAdapter retains the unique causing value sequence force error
Hi gurus BPEL.
I am facing a problem in EBS integration of the invoice of the OTM.
AP invoice header is inserted, the AP invoice lines does not get inserted due to the below error in BPEL. Import of payment fails, as there are no invoice lines.
Anomaly of the non-recoverable system:
Exception occurred when the link was invoked. Exception occurred during invocation of the JCA binding: "JCA binding run reference"insert"operations have to: DBWriteInteractionSpec Execute Failed Exception." insertion failed. The descriptor name: [APInvoice.ApInvoicesInterface]. Caused by java.sql.BatchUpdateException: ORA-00001: unique constraint (AP. AP_INVOICE_LINES_INTERFACE_U1) violated. Check the logs for the record output full DBAdapter before this exception. This exception is considered non reproducible, probably due to an error of modeling. To be classified as reproducible rather add property nonRetriableErrorCodes with the value "-1" for the deployment descriptor (i.e. weblogic - RA.Xml). Auto retry a reproducible fault set composite.xml for this invoke these properties: jca.retry.interval, jca.retry.count and jca.retry.backoff. All properties are integers. ". The called JCA adapter threw an exception of resource. Please review the error message above carefully to determine a resolution.
SOA DB Connections seem to retain the sequence used in the cache and assign the same when the Bill for the line is inserted. This causes the Unique constraint error when inserting the table of AP invoice lines in EBS.I call the standard APInvoices.wsdl to make the insertion AP_INVOICE_LINES_INTERFACE. I noticed that in the file APInvoice - or - mappings.xml contains the following code
> the sequence name < AP_INVOICE_LINES_INTERFACE_S < / sequence-name >
< table sequence-field = "AP_INVOICE_LINES_INTERFACE" name = "INVOICE_LINE_ID" / >
< / sequencing >
< cache >
weak-reference < cache-type > < / type of cache >
<-cache size >-1 < / cache size >
true < always refresh > - < / always refresh >
< / cache >
< remote caching >
weak-reference < cache-type > < / type of cache >
<-cache size >-1 < / cache size >
< / remote caching >Is their anything I can change something in the BPEL process to refresh the cache of the sequence all the time.
Alternative, I think now is below.
1. check with customer if they can do the sequence AP_INVOICE_LINES_INTERFACE_S as NOCACHE.
2. pull the invoice line via pl/sql adapter and complete the invoice line. But in this case, I'm not sure if Web APInvoice service code will try to update with the generated BPEL sequence.Any direction on this issue will be of great help.
Thank you
ShobzHi Anushal,
Thanks for the reply.Hi all
The problem has been resolved with the creation of this «sequencePreallocationSize» DBAdpater
As this property is set to 50 DB adapter's default, it did not fit with the INCREMENT BY the AP_INVOICE_LINES_INTERFACE_S sequence that has been set to 1.What happens in the adaptor DB is, when the first record is created, it takes the nextval in the sequence (assume it is 20), however it uses then his own sequence internal for the next 50 files by reference to the value set in this property (by creating records with primary keys from 20 to 70) and only when this internal sequence is exhausted it will return to the sequence of database.
Meanwhile, any other inovoice created AP would recover DB, which could be his word to say value 21, in conflict with the inserted by BPEL, throw a unique constraint.Setting this property to 1 or corresponding increment sequence solved the problem.
Thank you
Shobz -
Unique constraint violation error
Hi all
I have a procedure called - FHM_DASHBOARD_PROC which inserts data into a table called FHM_DASHBOARD_F retrieve records in multiple tables. However, for a particular type of record, these data are not inserted because of the Unique constraint violation
the procedure is:
and the table where data integration iscreate or replace PROCEDURE FHM_DASHBOARD_PROC AS DB_METRICS_CNT1Z number; --V_PODNAME varchar2(10); V_KI_CODE_DB_STATSZ varchar2(50); V_ERRORSTRING varchar2(100); --CURSOR PODNAME_CUR IS SELECT PODNAME,SHORTNAME FROM CRMODDEV.POD_DATA WHERE PODSTATUS_ID=1 AND PODTYPE_ID=1 ORDER BY PODNAME; -- DB STATS BEGIN -- OPEN PODNAME_CUR; -- LOOP -- FETCH PODNAME_CUR INTO V_PODNAME,V_POD_SHORTNAME ; -- EXIT WHEN PODNAME_CUR%NOTFOUND; BEGIN SELECT COUNT(*) INTO DB_METRICS_CNT1Z FROM FHM_DB_METRICS_F A, FHM_DB_D B where A.DBNAME=B.DBNAME and PODNAME=V_PODNAME AND DB_DATE=TRUNC(SYSDATE-1); DBMS_OUTPUT.PUT_LINE('DB_METRICS_CNT1Z :'|| DB_METRICS_CNT1Z); IF DB_METRICS_CNT1Z >0 THEN DBMS_OUTPUT.PUT_LINE('DB STATS'); INSERT INTO FHM_DASHBOARD_F(PODNAME,DASH_DATE,KI_CODE,KI_VALUE,KI_STATUS) (SELECT PODNAME, DASH_DATE AS CU_DATE, KI.KI_CODE, NVL(PF.KI_VALUE,0), CASE WHEN PF.KI_VALUE = ki.warning_threshold then 2 when PF.KI_VALUE=0 then 0 ELSE 1 END AS ALERT_STATUS FROM (SELECT PODNAME,DB_DATE AS DASH_DATE,decode(a.stats_last_status,'SUCCEEDED',1,'FAILED',2,'STOPPED',2,NULL,0) KI_VALUE from FHM_DB_METRICS_F a,fhm_db_d b where a.dbname=b.dbname and podname='XYZ' and db_date=TRUNC(SYSDATE-1) and dbtype='OLTP')PF, FHM_KEY_INDICATOR_D KI where PF.PODNAME=KI.POD_NAME AND KI.TIER_CODE=3 AND KI.KI_NAME='DB_STATS' AND (PF.PODNAME,TRUNC(PF.DASH_DATE),KI.KI_CODE) NOT IN (SELECT PODNAME,DASH_DATE,KI_CODE FROM FHM_DASHBOARD_F)); COMMIT; ELSE SELECT KI_CODE INTO V_KI_CODE_DB_STATSZ FROM FHM_KEY_INDICATOR_D WHERE POD_NAME=V_PODNAME AND KI_NAME='DB_STATS'; DBMS_OUTPUT.PUT_LINE('V_KI_CODE_DB_STATSZ :'||V_KI_CODE_DB_STATSZ); INSERT INTO FHM_DASHBOARD_F(PODNAME,DASH_DATE,KI_CODE,KI_VALUE,KI_STATUS) VALUES(V_PODNAME,TRUNC(SYSDATE-1),V_KI_CODE_DB_STATSZ,0,0); COMMIT; END IF; EXCEPTION WHEN OTHERS THEN V_ERRORSTRING :='INSERT INTO FHM_DASHBOARD_F_ERROR_LOG(POD_NAME,KI_NAME,ERRORNO,ERRORMESSAGE,DATETIME) VALUES ('''||V_PODNAME||''',''DB_STATS'','''||SQLCODE||''','''||SQLERRM||''',SYSDATE)'; EXECUTE IMMEDIATE V_ERRORSTRING; COMMIT; END; --END LOOP; --CLOSE PODNAME_CUR; END; END FHM_DASHBOARD_PROC;
the constraint primary key is FHM_DASHBOARD_F_DATE_PK and is on 3 columns of the table, DASH_DATE, PODNAME, KI_CODECREATE TABLE "CRMODDEV"."FHM_DASHBOARD_F" ( "PODNAME" VARCHAR2(25 BYTE) NOT NULL ENABLE, "DASH_DATE" DATE, "KI_CODE" NUMBER NOT NULL ENABLE, "KI_VALUE" NUMBER, "KI_STATUS" NUMBER, CONSTRAINT "FHM_DASHBOARD_F_DATE_PK" PRIMARY KEY ("DASH_DATE", "PODNAME", "KI_CODE") USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255 NOLOGGING COMPUTE STATISTICS STORAGE(INITIAL 4194304 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645 PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT) TABLESPACE "CRMODDEV_IDX" ENABLE, CONSTRAINT "FHM_DASHBOARD_F_KI_CODE_FK" FOREIGN KEY ("KI_CODE") REFERENCES "CRMODDEV"."FHM_KEY_INDICATOR_D" ("KI_CODE") ENABLE ) PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 NOCOMPRESS NOLOGGING STORAGE ( INITIAL 3145728 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645 PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT ) TABLESPACE "CRMODDEV_TBL" ENABLE ROW MOVEMENT ;
And it's the query used in the procedure to insert the data into the table
It gives * record * 2 suite(SELECT PODNAME, DASH_DATE AS CU_DATE, KI.KI_CODE, NVL(PF.KI_VALUE,0), CASE WHEN PF.KI_VALUE = ki.warning_threshold then 2 when PF.KI_VALUE=0 then 0 ELSE 1 END AS ALERT_STATUS From (Select Podname,Db_Date As Dash_Date,Decode(A.Stats_Last_Status,'SUCCEEDED',1,'FAILED',2,'STOPPED',2,Null,0) Ki_Value From -- Added Distinct FHM_DB_METRICS_F a,fhm_db_d b where a.dbname=b.dbname and podname in ('XYZ') and db_date = TRUNC(SYSDATE-2) and dbtype='OLTP')PF, Fhm_Key_Indicator_D Ki Where Pf.Podname=Ki.Pod_Name And Ki.Tier_Code=3 And Ki.Ki_Name='DB_STATS' And (Pf.Podname,Trunc(Pf.Dash_Date),Ki.Ki_Code) Not In (Select Podname,Dash_Date,Ki_Code From Fhm_Dashboard_F));
---------------------------------------
XYZ JANUARY 20 12 2521 1 1
XYZ JANUARY 20 12 2521 1 1
It gives the Unique constraint violation error when inserting. Then, I changed in the above insertion code by adding a distinct clause. Once the query gives only a SINGLE record accordingly. However, this record is not be inserted into the table and give the same error.
Now the question is how should I insert that record into the table with success?
If the message is too long, however, I gave you the real structure of the object or procedure and error.
Thank you in advance.When you have 5 columns in the game adding THAT SEPARATE is n ot solution that you can still get the same error once.
Check the target table if the data exists before inserting... If this is not the case, check the structure of the table for a unique constraint created on other columns.
select *from
where DASH_DATE=date '2012-01-20' and PODNAME='XYZ' and KI_CODE=2521; -
Disable the unique key constraint
Hello
Is it possible to disable a unique key constraint?
I tried the following code:
ALTER TABLE table_name
DISABLE the CONSTRAINT uk_constraint_name
that seems to work fine, but when I try to insert or update a record that the unique constraint is still on. However, Toad in the United Kingdom is marked as disabled.
What do I need to drop the UK and re-create it after my updates?
Thank youThe behavior that I have demonstrated that during
a. you have an existing UNIQUE Index
b. you add a Unique key constraint (with the same or another name, any - except that the error message contains the name of the index is different, if the constraint is disabled)OTOH, if you set the Unique key on the table without pre-existing index constraint, Oracle creates an Index. If you disable this constraint, Oracle removes the Index.
So, if it is a small table and you can afford to recreate the Index each time, you can follow this method.SQL> create table t_2 (col_1 number, col_2 varchar2(5)); Table created. SQL> alter table t_2 add constraint t_2_uk unique (col_1); Table altered. SQL> select index_name, uniqueness, status from user_indexes where table_name = 'T_2'; INDEX_NAME UNIQUENES STATUS ------------------------------ --------- -------- T_2_UK UNIQUE VALID SQL> insert into t_2 values (1,'a'); 1 row created. SQL> commit; Commit complete. SQL> alter table t_2 disable constraint t_2_uk; Table altered. SQL> insert into t_2 values (1,'b'); 1 row created. SQL> select index_name, uniqueness, status from user_indexes where table_name = 'T_2'; no rows selected SQL>SQL> select constraint_name, constraint_type, status from user_constraints where table_name = 'T_2'; CONSTRAINT_NAME C STATUS ------------------------------ - -------- T_2_UK U DISABLED SQL> alter table t_2 enable constraint t_2_uk; alter table t_2 enable constraint t_2_uk * ERROR at line 1: ORA-02299: cannot validate (AWRADMIN.T_2_UK) - duplicate keys found SQL> delete t_2 where col_2 = 'b'; 1 row deleted. SQL> alter table t_2 enable constraint t_2_uk; Table altered. SQL> select index_name, uniqueness, status from user_indexes where table_name = 'T_2'; INDEX_NAME UNIQUENES STATUS ------------------------------ --------- -------- T_2_UK UNIQUE VALID SQL>
Hemant K Collette
-
Index naming standards does not and unique constraints
I found yet another question of naming standards
I have tried to create a unique constraint as a normal index via the unique constraints and indexes in Properties of Table with the assumption that it will use the design properties of models. This isn't.
As noted in the image of the model above, my Unique constraint model is {table} _ {columns} lancement_remarques
and my model of Index idx _ {columns} {table}. Yet, when I try to create the Unique constraint, it creates the naming convention in names like CUSTOMER_ADDRESS__UK (2 lines of underscore?) as shown below.
My assumption is that he needed a column, so I added the column and also applied the rules naming - nothing.
Is my wrong assumption on these constraints being appointed through the models? If this is not the case, what naming rules is in this context?
The same behavior is evident when you try to create index.
I get not all comments on my posts. Are these bugs or just user error?
Hello
Thank you to report the problem, I logged a bug. You can get 'Rules of naming' works properly if you press the button 'Apply' before that.
I get not all comments on my posts.
I don't think that anyone (or any job) has been ignored on this forum. Depending on the complexity of the problem and our current commitment (other urgent tasks, holidays, time zone), you can get answer almost immediately or after a certain time.
It is useful for us, if you mark your messages as replied if you get the right answer.
Philippe
-
Adding a UNIQUE CONSTRAINT to an existing column with duplicate values
Oracle Forums Hello, I have a table that contains rows 11 901. I tried to define the UNIQUE constraint on the column of xcode, but encountered an error: the column already contain duplicates! I rescued following SQL 'SELECT COUNT (*) FROM States;' the result is 11 901 and 'SELECT COUNT (DISTINCT (xcode)) FROM States;' the result is 11 680. So to enforce this unique key I have to remove the 221 lines. Please how can I do this?REMOVE duplicates...
For example, as
delete from your_table t where rowid < ( select max(rowid) from your_table r where t.unique_column = r.unique_column);
Thne create the constraint.
-
I just got an error of constraint unique violation when I tried to insert a row in a table.
But even after that I deleted the PK constraint on the table in question, I still get the same error message when I try again the insert:
SQL error: ORA-00001: unique constraint (GILLNET_TAG. DELETED_AUTH_PK) violated
00001 00000 - "forced single (s.%s) violated."
* Cause: An UPDATE or INSERT statement attempted to insert a duplicate key.
For Trusted Oracle configured in DBMS MAC mode, you can see
This message if there is an entry double at a different level.
* Action: Either remove the single restriction or not to insert the key.
Can someone tell me why? The removal of the constraint simply not registered with SQL Developer?
Thank you.Because you have only removed the constraint, not the corresponding unique index.
But... Why are you doing it? The unique constraint is there for a reason.
-
Violation of unique constraint in JPA in multiple threads
I get the following error message when you use APP to create a record in my database:
# < 14 October 2009 10:13:14 AM CDT > < Info > < EJB > < lharding pc > < AdminServer > < ExecuteThread [ASSET]: '3' for queue: '(self-adjusting) weblogic.kernel.Default' > < < anonymous > > < BEA1 003262EA920A3057A4BD > <>< 1255533194632 > < BEA-010227 > < EJB Exception occurred during invocation of home or business: weblogic.ejb.container.internal.StatelessEJBHomeImpl@589d49 threw the exception : javax.persistence.PersistenceException: Exception [EclipseLink-4002] (Eclipse - 1.1.0.r3338 - M8 persistence Services): org.eclipse.persistence.exceptions.DatabaseException
Inner exception: java.sql.SQLIntegrityConstraintViolationException: ORA-00001: unique constraint (BDSS. CONN_USER_DOMAIN_STATE_PK) violated
Error code: 1
Call: INSERT INTO USER_CONTEXT_STATES (ID, TEMP_FLG, STATE_INDEX, LAST_SYNC_TS, USER_CONTEXT_ID) VALUES (?,?,?,?,?)
link = > [12701, 100003, T, null, null]
Query: InsertObjectQuery (oracle.bdss.datamodel.UserContextStates@a4af11) >
I do the work of an EJB on Weblogic Server and I used the JDev "Entities of Tables" Wizard to generate the code for each table.
The code works fine most of the time. However when there are multiple threads using the EJB, I think that the allocation of the sequence becomes the same set IDS on different threads. The Session Cache for my persistence has the default "(soft low)".
Everyone seems it before and you know a solution?
The annotations that I use for the generation of PK for the ID column (where the unique constraint is violated) are:
@Id
@Column (nullable = false)
@TableGenerator (name = "UserContextStatesSeq", table = "SÉQUENCE",
scheme = "SDE", pkColumnName = "SEQ_NAME,"
valueColumnName = "SEQ_COUNT"
pkColumnValue = "BDSS. USER_CONTEXT_STATES «(, allocationSize = 50).
@GeneratedValue (strategy = GenerationType.TABLE,
generator = "UserContextStatesSeq")
Private Long id;
The code for the EJB is shown below (only the relevant parts):
@Stateless (name = "RuntimeEJBBean")
@Local
public class RuntimeEJBBean
implements RuntimeEJBLocal
{
@PersistenceContext (unitName = "persist")
Private EntityManager em;
public RuntimeEJBBean()
{
}
Private Sub createNewContextState()
throws the Exception
{
NewState UserContextStates = null;
Try
{
newState = new UserContextStates();
EM. Persist (newState);
...
EM. Flush();
catch (System.Exception e)
{
...
}
}According to your annotation you use table named SEQUENCE to generate the id I suggest switching to sequence if you use Oracle.
So instead of
@TableGenerator (name = "UserContextStatesSeq", table = "SÉQUENCE",
scheme = "SDE", pkColumnName = "SEQ_NAME,"
valueColumnName = "SEQ_COUNT"
pkColumnValue = "BDSS. USER_CONTEXT_STATES «(, allocationSize = 50).
@GeneratedValue (strategy = GenerationType.TABLE,
generator = "UserContextStatesSeq")use
@SequenceGenerator (name = "UserContextStatesSeq", sequenceName = "USER_CONTEXT_STATES_ID", allocationSize = 1)
@GeneratedValue (generator = "UserContextStatesSeq")and db to create sequences:
CREATE THE SER_CONTEXT_STATES_ID MINVALUE SEQUENCE 1 WITH AN INCREMENT BY 1 1 COVER 50 ALL;
allocationSize = 1 in @SequenceGenerator with CACHE 50 in phrase makes any id generation caching done at Oracle no ORM.
If go to the sequence isn't an option, I would check if all error a bind ID with values such as XXXX01 or XXXX51. If Yes, then taking into account the fact that you have allocationSize = 50, it would mean that EclipseLink does not correctly synchronize award of the new id if that's the case then maybe change allocationSize 1 would help.
-
correct handling of foreign keys in unique constraints for operations ON DELETE SET NULL
During my troubleshooting at a client site, I came across an interesting setup where I would like to ask your opinion.
Consider two tables ADTB and TBLB.ADTB:
INT COLA1
COLA2 INT
TBLB:
COLB1 INT
COLA2 is COLB1 as a foreign key ON DELETE SET NULL value.
COLA1 and COLA2 are combined into a UNIQUE for the BATTERY constraint.
I have two records of TBLB:
(1)
(2)
and two DRUM recordings:
(1, 1)
(2, 2)
so far, all the constraints are valid.
During my research, I learned that I can not put COLA2 null in ADTB for two lines at the same time:
TBLA UPDATE set COLA2 = NULL where COLA1 = 1;
-> OK
TBLA UPDATE set COLA2 = NULL where COLA1 = 2;
-> VIOLATED UNIQUE CONSTRAINT
Unfortunately, it's something my application needs, anyway. In order to get this resolved, but I try to understand, what would happen if I:
REMOVE THE TBLB;
?
It should set COLA2 in ADTB "Null" on the two lines, which is not allowed due to the UNIQUE CONSTRAINT.
Can someone shed light on this issue? Thank you.
Yours,Ronny
Unfortunately, as you say, you can't not NULL values in such a unique constraint. It would be the same as if you had a composite primary key and try to allow one of the columns will be null in several rows with the same value in the other column. NULL is treated as an "unknown" value, it is possible that it could be the same value (it may or may not be, but Oracle does not know), so it must assume that it might be and that's why treat it as if there is the potential for a duplicate... so it's not unique.
In short, do not allow null values in your unique constraints.
The default is in the drawing, not in the way that Oracle is the treatment. Fix the design if you do not have NULL values.
In terms of relational database design, it seems that you are trying to transform the 1:M relations M:M relations, and which requires an intermediate table if you have M:1 and 1:M between 3 tables instead.
-
Customized for a Unique constraint processing scripts
Hallo,
How can I create the Unique constraint (not a Unique Index) transformation scripts:
var key_column = 'KEY'; // get tables tables = model.getTableSet().toArray(); for (var t = 0; t < tables.length;t++){ table = tables[t]; table_name = table.getName(); abbr = table.getAbbreviation()+"_"; key_col = table.getElementByName(key_column); if (key_col!=null){ uniq = table.createIndex(); // it is right? table.setDirty(true); uniq.setName('UNIQUE'); // does not matter uniq.add(id3_col); uniq.setUK(true); // a method does not exist table.setUK(uniq);// a method does not exist } }
regarding
Oleg
Hello Oleg,
lines 14 and 15 are false. The use of the persistence method is:
uniq.setIndexState ("Unique constraint");
Other options here - you can spot if you look at the XML file representing the table with PK and UK constraints and regular index - "primary constraint, «Unique Index ordinary', «Clear index»»
Philippe
-
Indexes and UNIQUE constraints
For a TEST table (col1, col2, col3,...), I put the UNIQUE constraint as follows:
ALTER table TEST add constraint test_uniq UNIQUE col1, col2, col3);
It is said that when the UNIQUE constraint is created, ORACLE also creates an index on (col1, col2, col3) automatically. But sometimes, I use only one of the columns in the WHERE clause as col1 = xxx, or col2 = yyy.
Create separate indexes, one for col1 and col2? I think that even if the creation of the UNIQUE constraint also created an index. But this index is a composite index that is for the dosage of col1, col2 and col3 simultaneously (is that correct)? If so, create an index for col1 and col2 will be necessary?
Thank you for helping.
ScottIf there is an index on (col1, col2, col3) and ask about col1, the index will be used.
If you have questions about col2, it can (index skip scan) or maybe not.
If you ask about col3 then it will not be used.
So if you think that there will be queries with col3 in where clause and they can benefit from an index, you can create it.
-
Unique constraint on data type Date
Hello
I have table below.
CREATE TABLE unique_date_check
(employee_id NUMBER,
amount NUMBER,
pay_date DATE default sysdate,
UNIQUE CONSTRAINT Uq_pay_date (pay_date));
The table should accept only a single amount per employee per pay_date.
I use sysdate as pay_date. Because sysdate has timestamp inside, check the unique constraint on both the date and time stamp.
I need uniqueness only on the part of date (i.e., dd/mm/yyyy), but not on the parking meter.
Should I use triggers for this or there at - it another way to meet my needs?
Thanks in advance.
NadineYou cannot declare a unique constraint based on a function, but you can create a unique index based on a function:
CREATE TABLE unique_date_check (employee_id NUMBER , amount NUMBER , pay_date DATE DEFAULT sysdate); create unique index uq_pay_date on unique_date_check(employee_id,trunc(pay_date));
Note that I added employee_id in the index, to match your requirements.
Triggers should not be at the top of your list of techniques to solve problems, particularly the requirements of validation that involve other lines.
-
Maximum Unique constraints Null values
Nulls howmany Maximum allowed in the Unique constraintThere is NO Limit to it. You can have a number any NULL value in a column with a Unique constraint.
Maybe you are looking for
-
TOSHIBA Power Saver of the Satellite Pro M series stopped working. (code 0 x 0)
The utility has suddenly stopped working after Windows XP update.Informed, that there was an irreparable failure and performance of the program will be interrupted.Code 0 x 0 What should do?
-
HP Deskjet 2540 all-in-one: HP Deskjet 2540 Scan works only in Windows 10
Have upgraded to Windows 10 (not sure if 32 or 64 bit). Now cannot scan. Have tried uninstalling/reinstalling, loading HP Print and Scan and HP Support Assistant doctor and does everything that is asked. However, the software that load every time
-
IR column headers are not displayed in a collapsible area on oracle apex
Hi allI packed a report interactive and region definition > model is defined as a foldable in Apex5.0.When I run this page it does not display the column headings in the report. Is there a property to set when we use the folding model?Thank youKetan
-
I have creative cloud on my mac. received a computer notebook pc
When I connect to creative cloud I can't access to HAVE. I can see four fonts that I have selected in Adobe Typefont. What I am doing wrong? Why not have I play on my PC?
-
How can I change my annual and monthly payment plan not
I need to renew my subscription cloud creative and want to pay for the entire year instead of monthly.Where to change it in the settings of my account?