![]() |
![]() |
|
No, this is not a bug. You have defined a join table that has 2 columns - the link back to the owner, and the element. Consequently the PK is formed from both. You insert the same element twice and you get a duplicate insert exception for the join table. Think about it. If you really want to allow dups then you provide an <order> definition so an extra column will be added to the join table. This is JDO2 standard way of doing things.
The only thing that needs changing is the response to HashSet.add to just return false.
I did raise on forum: http://www.jpox.org/servlet/forum/viewthread?thread=2900
If your solution is to not throw an exception but instead return false from HashSet.add(), that sounds correct to me. Yes. I found the forum issue raised ... later on. Was going down and checking which issues had the "URL" field not filled in.
With regards to the original issue, it is a bug (in the HashSet.add), and is now reopened. I read it as some problem with not allowing dups when it should, yet it is for a Set which doesnt allow dups under any circumstances. Moral of the story ... don't give issues a cursory glance after a 8 hour coach journey, wait til the next day :-) add(), addAll() fixed in CVS for all set-based collections
|
|||||||||||||||||||||||||||||||||||||||||||
CREATE TABLE `a` (
`JDOCLASSX` varchar(255) default NULL,
`JDOIDX` bigint(20) NOT NULL default '0',
`JDOLOCKX` int(11) default NULL,
`name` varchar(255) default NULL,
PRIMARY KEY (`JDOIDX`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
CREATE TABLE `a_set` (
`JDOIDX` bigint(20) NOT NULL default '0',
`item` smallint(6) NOT NULL default '0',
PRIMARY KEY (`JDOIDX`,`item`)
ENGINE=InnoDB DEFAULT CHARSET=latin1;
Exception on running test:
javax.jdo.JDODataStoreException: Add request failed : INSERT INTO `A_SET` (`JDOI
DX`,`ITEM`) VALUES (?,?)
at org.jpox.store.rdbms.scostore.NormalSetStore.add(NormalSetStore.java:
568)
at org.jpox.sco.HashSet.add(HashSet.java:590)
at org.jpox.test.A.add(A.java:27)
at org.jpox.test.Main.main(Main.java:88)
NestedThrowablesStackTrace:
java.sql.SQLException: Duplicate entry '1-1' for key 1
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2928)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1571)
at com.mysql.jdbc.ServerPreparedStatement.serverExecute(ServerPreparedSt
atement.java:1124)
at com.mysql.jdbc.ServerPreparedStatement.executeInternal(ServerPrepared
Statement.java:676)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java
:1166)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java
:1082)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java
:1067)
at org.jpox.store.rdbms.scostore.BaseContainerStore.executeUpdate(BaseCo
ntainerStore.java:104)
at org.jpox.store.rdbms.scostore.NormalSetStore.add(NormalSetStore.java:
550)
at org.jpox.sco.HashSet.add(HashSet.java:590)
at org.jpox.test.A.add(A.java:27)
at org.jpox.test.Main.main(Main.java:88)
>> Failed to add duplicate to set Add request failed : INSERT INTO `A_SET` (`JDOIDX`,`ITEM`) VALUES (?,?)