Skip to content

Commit 6138799

Browse files
committed
fix(backend): use native INSERT for import Activity rows (JSONB cast)
Hibernate binds String → varchar by default; the `diff_json` column is JSONB, so an INSERT with the JPA Activity entity fails with `column "diff_json" is of type jsonb but expression is of type character varying` — all 9 import/export integration tests tripped on this on first write (import seeds translations via the service). Mirror the existing `KeyService.writeActivity` native-SQL INSERT so the column type stays happy until Phase 7 (T706) back-fills structured diff payloads. No behaviour change; the entity write path wasn't being used elsewhere. Drops the `Activity` import since we no longer construct the entity.
1 parent 7e84e1c commit 6138799

1 file changed

Lines changed: 17 additions & 8 deletions

File tree

backend/service/src/main/kotlin/io/translately/service/translations/TranslationImportService.kt

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package io.translately.service.translations
22

3-
import io.translately.data.entity.Activity
3+
import io.translately.data.Ulid
44
import io.translately.data.entity.ActivityType
55
import io.translately.data.entity.Key
66
import io.translately.data.entity.KeyState
@@ -246,13 +246,22 @@ open class TranslationImportService {
246246
caller: User?,
247247
type: ActivityType,
248248
) {
249-
val activity =
250-
Activity().apply {
251-
this.key = key
252-
this.actor = caller
253-
this.actionType = type
254-
}
255-
em.persist(activity)
249+
// Native INSERT sidesteps the JPA `String` → JSONB parameter-type
250+
// mismatch on `diff_json`. Mirrors `KeyService.writeActivity`; the
251+
// Phase 7 audit log (T706) back-fills structured payloads.
252+
em
253+
.createNativeQuery(
254+
"""
255+
INSERT INTO key_activity
256+
(external_id, key_id, actor_user_id, action_type, diff_json, created_at, updated_at)
257+
VALUES
258+
(?1, ?2, ?3, ?4, NULL, NOW(), NOW())
259+
""".trimIndent(),
260+
).setParameter(1, Ulid.generate())
261+
.setParameter(2, key.id)
262+
.setParameter(3, caller?.id)
263+
.setParameter(4, type.name)
264+
.executeUpdate()
256265
}
257266

258267
private fun findKey(

0 commit comments

Comments
 (0)