Issue Details (XML | Word | Printable)

Key: OPENJPA-284
Type: Bug Bug
Status: Closed Closed
Resolution: Fixed
Priority: Major Major
Assignee: Unassigned
Reporter: Teresa Kan
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
OpenJPA

TableJDBCSeq for GeneratedValue.TABLE did not handle initialValue correctly

Created: 16/Jul/07 02:11 PM   Updated: 07/Aug/07 05:39 PM
Return to search
Component/s: jdbc
Affects Version/s: 1.0.0
Fix Version/s: 1.0.0

Time Tracking:
Not Specified

File Attachments:
  Size
Text File OPENJPA-284.patch 2007-07-16 06:36 PM Teresa Kan 2 kB
Environment: Window XP, JDK 1.5

Resolution Date: 07/Aug/07 05:00 PM


 Description  « Hide
When I tested the GeneratedValue strategy on TABLE, and I found a bug in the TableJDBCSeq that did not set the InitalValue. Therefore, the sequence always start from 1.
Here are the bugs in the TableJDBCSeq:
1) InsertSequence method:
       SQLBuffer insert = new SQLBuffer(dict).append("INSERT INTO ").
            append(_pkColumn.getTable()).append(" (").
            append(_pkColumn).append(", ").append(_seqColumn).
            append(") VALUES (").
            appendValue(pk, _pkColumn).append(", ").
            appendValue(Numbers.valueOf(1), _seqColumn).append(")"); --> Always set the initial value to 1.
2) no getter and setter on the InitialValue.

Here is the annotation:
@TableGenerator(name="Dog_Gen", table ="ID_Gen", pkColumnName="GEN_NAME", valueColumnName="GEN_VAL",pkColumnValue="ID2",initialValue=20,allocationSize=10)
@GeneratedValue(strategy=GenerationType.TABLE, generator="Dog_Gen")
private int id2;

The initial value always started from 1 with the current openjpa implementation.
The fix will be like this:
1) add getter and setter of InitialValue in TableJDBCSeq .
2) add int _initValue variable.
3) Change the InsertSequence method:
       SQLBuffer insert = new SQLBuffer(dict).append("INSERT INTO ").
            append(_pkColumn.getTable()).append(" (").
            append(_pkColumn).append(", ").append(_seqColumn).
            append(") VALUES (").
            appendValue(pk, _pkColumn).append(", ").
            appendValue(_intValue, _seqColumn).append(")"); ---> change to use the initValue instead of 1.



 All   Comments   Work Log   Change History   Subversion Commits      Sort Order: Ascending order - Click to sort in descending order
Teresa Kan added a comment - 16/Jul/07 06:36 PM
The patch is provided for this jiar report

Teresa Kan made changes - 16/Jul/07 06:36 PM
Field Original Value New Value
Attachment OPENJPA-284.patch [ 12361905 ]
Repository Revision Date User Message
ASF #558097 Fri Jul 20 19:17:19 UTC 2007 mikedd OPENJPA-284 committing on behalf of Teresa
Files Changed
ADD /openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/generationtype/TestTableGenerator.java
MODIFY /openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/TableJDBCSeq.java
ADD /openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/generationtype/Dog.java

Patrick Linskey made changes - 07/Aug/07 05:00 PM
Resolution Fixed [ 1 ]
Status Open [ 1 ] Resolved [ 5 ]
Craig Russell made changes - 07/Aug/07 05:01 PM
Fix Version/s 1.0.0 [ 12312341 ]
Michael Dick made changes - 07/Aug/07 05:39 PM
Status Resolved [ 5 ] Closed [ 6 ]