Commit 393d9fa
GH-3442: Fix MySQL/MariaDB message ordering in JdbcChatMemoryRepository
Fixes #3442
Change timestamp generation to use second-level granularity instead of
milliseconds to ensure compatibility with MySQL/MariaDB default TIMESTAMP
precision (0 decimal places). The old code used millisecond timestamps that
were truncated to seconds on storage, causing messages saved within the same
second to have identical timestamps and random ordering.
The timestamp field functions as a sequence ID for message ordering rather
than a precise temporal record. Using second-level granularity with proper
incrementing ensures correct ordering across all database timestamp precisions
without requiring schema changes.
Also adds testMessageOrderWithLargeBatch() that saves 50 messages to validate
ordering is preserved. The original test with only 4 messages was passing by
chance despite the underlying bug.
Signed-off-by: Soby Chacko <[email protected]>
(cherry picked from commit d2492a6)1 parent 9d3d7e1 commit 393d9fa
File tree
2 files changed
+32
-3
lines changed- memory/repository/spring-ai-model-chat-memory-repository-jdbc/src
- main/java/org/springframework/ai/chat/memory/repository/jdbc
- test/java/org/springframework/ai/chat/memory/repository/jdbc
2 files changed
+32
-3
lines changedLines changed: 8 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
111 | 111 | | |
112 | 112 | | |
113 | 113 | | |
114 | | - | |
| 114 | + | |
115 | 115 | | |
116 | 116 | | |
117 | | - | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
118 | 121 | | |
119 | 122 | | |
120 | 123 | | |
| |||
124 | 127 | | |
125 | 128 | | |
126 | 129 | | |
127 | | - | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
128 | 133 | | |
129 | 134 | | |
130 | 135 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
186 | 186 | | |
187 | 187 | | |
188 | 188 | | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
189 | 213 | | |
190 | 214 | | |
191 | 215 | | |
| |||
0 commit comments