User 247c00dc1d
05-09-2014 11:24:20
Hello,
I need make relationship of many-to-many type between two tables, but actually I can't do it...
table 1:
id | Linked_field1 |
1 | 123 |
2 | 123 |
3 | 568 |
4 | 78 |
table 2:
Linked_field1 | val_field |
123 | 5.86 |
123 | 6.86 |
123 | 24.3 |
78 | 1.3 |
568 | 78.4 |
568 | 62.3 |
568 | 0.12 |
and for example for record with id 2 from 1st table should be shown all three records from 2nd table.
when I try to make many-to-many relationship I get error
org.springframework.dao.DataIntegrityViolationException: The relationship could not be created. One of the fields was not REQUIRED, which may cause unique constraint creation failure on some databases. If this is the case, set both fields to REQUIRED.
The original error was:
StatementCallback; SQL [ALTER TABLE APP.SAMPLE ADD CONSTRAINT UK_FK_SAMPLE UNIQUE (COMPOUND_ID)]; The statement was aborted because it would have caused a duplicate key value in a unique or primary key constraint or unique index identified by 'SQL140905142228830' defined on 'SAMPLE'.; nested exception is java.sql.SQLIntegrityConstraintViolationException: The statement was aborted because it would have caused a duplicate key value in a unique or primary key constraint or unique index identified by 'SQL140905142228830' defined on 'SAMPLE'.
; nested exception is org.springframework.dao.DuplicateKeyException: StatementCallback; SQL [ALTER TABLE APP.SAMPLE ADD CONSTRAINT UK_FK_SAMPLE UNIQUE (COMPOUND_ID)]; The statement was aborted because it would have caused a duplicate key value in a unique or primary key constraint or unique index identified by 'SQL140905142228830' defined on 'SAMPLE'.; nested exception is java.sql.SQLIntegrityConstraintViolationException: The statement was aborted because it would have caused a duplicate key value in a unique or primary key constraint or unique index identified by 'SQL140905142228830' defined on 'SAMPLE'.
at com.im.df.impl.db.DBRelationshipMtoNNT.create(DBRelationshipMtoNNT.java:84)
at com.im.ijc.core.wizards.newdfitem.NewDFItemWizardPanel1$2.phase1InRequestProcessor(NewDFItemWizardPanel1.java:140)
at com.im.commons.progress.BackgroundRunner.processTheTask(BackgroundRunner.java:133)
at com.im.commons.progress.BackgroundRunner$1.run(BackgroundRunner.java:96)
at org.openide.util.RequestProcessor$Task.run(RequestProcessor.java:1411)
at org.openide.util.RequestProcessor$Processor.run(RequestProcessor.java:1991)
Caused by: org.springframework.dao.DuplicateKeyException: StatementCallback; SQL [ALTER TABLE APP.SAMPLE ADD CONSTRAINT UK_FK_SAMPLE UNIQUE (COMPOUND_ID)]; The statement was aborted because it would have caused a duplicate key value in a unique or primary key constraint or unique index identified by 'SQL140905142228830' defined on 'SAMPLE'.; nested exception is java.sql.SQLIntegrityConstraintViolationException: The statement was aborted because it would have caused a duplicate key value in a unique or primary key constraint or unique index identified by 'SQL140905142228830' defined on 'SAMPLE'.
at org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator.doTranslate(SQLErrorCodeSQLExceptionTranslator.java:245)
at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:72)
at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:407)
at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:428)
at com.im.ijcs.impl.ddl.TableManagerImpl.addUniqueConstraint(TableManagerImpl.java:434)
at com.im.ijcs.impl.ddl.operations.constraint.AddUniqueConstraintOperation.executeImpl(AddUniqueConstraintOperation.java:105)
at com.im.ijcs.impl.ddl.operations.AbstractOperation.execute(AbstractOperation.java:117)
at com.im.ijcs.impl.ddl.DefaultDDLService.performOperations(DefaultDDLService.java:860)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:317)
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:96)
at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:260)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:94)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
at com.sun.proxy.$Proxy20.performOperations(Unknown Source)
at com.im.df.impl.db.DBSchemaImpl.applyOperations(DBSchemaImpl.java:1062)
at com.im.df.impl.db.DBRelationshipNT.createNew(DBRelationshipNT.java:136)
at com.im.df.impl.db.DBRelationshipMtoNNT.create(DBRelationshipMtoNNT.java:75)
... 5 more
Caused by: java.sql.SQLIntegrityConstraintViolationException: The statement was aborted because it would have caused a duplicate key value in a unique or primary key constraint or unique index identified by 'SQL140905142228830' defined on 'SAMPLE'.
at org.apache.derby.impl.jdbc.SQLExceptionFactory40.getSQLException(Unknown Source)
at org.apache.derby.impl.jdbc.Util.generateCsSQLException(Unknown Source)
at org.apache.derby.impl.jdbc.TransactionResourceImpl.wrapInSQLException(Unknown Source)
at org.apache.derby.impl.jdbc.TransactionResourceImpl.handleException(Unknown Source)
at org.apache.derby.impl.jdbc.EmbedConnection.handleException(Unknown Source)
at org.apache.derby.impl.jdbc.ConnectionChild.handleException(Unknown Source)
at org.apache.derby.impl.jdbc.EmbedStatement.executeStatement(Unknown Source)
at org.apache.derby.impl.jdbc.EmbedStatement.execute(Unknown Source)
at org.apache.derby.impl.jdbc.EmbedStatement.execute(Unknown Source)
at org.apache.commons.dbcp.DelegatingStatement.execute(DelegatingStatement.java:264)
at org.apache.commons.dbcp.DelegatingStatement.execute(DelegatingStatement.java:264)
at org.apache.commons.dbcp.DelegatingStatement.execute(DelegatingStatement.java:264)
at org.springframework.jdbc.core.JdbcTemplate$1ExecuteStatementCallback.doInStatement(JdbcTemplate.java:421)
at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:396)
... 26 more
Caused by: java.sql.SQLException: The statement was aborted because it would have caused a duplicate key value in a unique or primary key constraint or unique index identified by 'SQL140905142228830' defined on 'SAMPLE'.
at org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(Unknown Source)
at org.apache.derby.impl.jdbc.SQLExceptionFactory40.wrapArgsForTransportAcrossDRDA(Unknown Source)
... 40 more
Caused by: ERROR 23505: The statement was aborted because it would have caused a duplicate key value in a unique or primary key constraint or unique index identified by 'SQL140905142228830' defined on 'SAMPLE'.
at org.apache.derby.iapi.error.StandardException.newException(Unknown Source)
at org.apache.derby.impl.sql.execute.UniqueWithDuplicateNullsIndexSortObserver.insertDuplicateKey(Unknown Source)
at org.apache.derby.impl.store.access.sort.SortBuffer.insert(Unknown Source)
at org.apache.derby.impl.store.access.sort.MergeInserter.insert(Unknown Source)
at org.apache.derby.impl.sql.execute.CreateIndexConstantAction.loadSorter(Unknown Source)
at org.apache.derby.impl.sql.execute.CreateIndexConstantAction.executeConstantAction(Unknown Source)
at org.apache.derby.impl.sql.execute.CreateConstraintConstantAction.executeConstantAction(Unknown Source)
at org.apache.derby.impl.sql.execute.AlterTableConstantAction.executeConstantActionBody(Unknown Source)
at org.apache.derby.impl.sql.execute.AlterTableConstantAction.executeConstantAction(Unknown Source)
at org.apache.derby.impl.sql.execute.MiscResultSet.open(Unknown Source)
at org.apache.derby.impl.sql.GenericPreparedStatement.executeStmt(Unknown Source)
at org.apache.derby.impl.sql.GenericPreparedStatement.execute(Unknown Source)
... 34 more
Thanks!
Igor.