Issue Details (XML | Word | Printable)

Key: CORE-2599
Type: Bug Bug
Status: Closed Closed
Resolution: Fixed
Priority: Minor Minor
Assignee: Andy Jefferson
Reporter: Clive Cox
Votes: 0
Watchers: 1
Operations

If you were logged in you would be able to see more operations.
JPOX Core (ARCHIVED)

Exception on attempting add duplicate SCO to HashSet

Created: 08/Dec/05 02:53 PM   Updated: 22/Jan/06 02:35 PM   Resolved: 13/Dec/05 07:42 AM
Component/s: JDO
Affects Version/s: 1.1.0-beta-5
Fix Version/s: 1.1.0-beta-6

File Attachments: 1. Zip Archive test.zip (2 kB)

Environment: MySQL

Forum Thread URL: http://www.jpox.org/servlet/forum/viewthread?thread=2900
Datastore: MySQL


 Description  « Hide
JPOX attempts to insert duplicate item into database for persisted HashSet of SCO instead of following HashSet semantics and not doing the insertion and returning false to HashSet.add()

This causes an exception of the form: java.sql.SQLException: Duplicate entry

TestCase to follow.


Sort Order: Ascending order - Click to sort in descending order
Clive Cox added a comment - 08/Dec/05 02:57 PM
Schemas:
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 (?,?)

Andy Jefferson added a comment - 12/Dec/05 07:49 PM
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.

Andy Jefferson added a comment - 12/Dec/05 08:16 PM
The only thing that needs changing is the response to HashSet.add to just return false.

Clive Cox added a comment - 12/Dec/05 10:19 PM
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.

Andy Jefferson added a comment - 13/Dec/05 05:47 AM
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 :-)

Andy Jefferson added a comment - 13/Dec/05 07:42 AM
add(), addAll() fixed in CVS for all set-based collections