Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Update Hibernate #2885

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ class V2ImportLanguagesController(

private fun checkImportLanguageInProject(languageId: Long): ImportLanguage {
val language = importService.findLanguage(languageId) ?: throw NotFoundException()
val languageProjectId = language.file.import.project.id
val languageProjectId = language.file.importEntity.project.id
if (languageProjectId != projectHolder.project.id) {
throw BadRequestException(io.tolgee.constants.Message.IMPORT_LANGUAGE_NOT_FROM_PROJECT)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ class ImportFileRepositoryTest : AbstractSpringTest() {
fun `creates and saves and gets ImportFile entity`() {
val import = createBaseImport()

ImportFile(import = import, name = "en.json").let {
ImportFile(importEntity = import, name = "en.json").let {
importFileRepository.save(it).let { saved ->
importFileRepository.getOne(saved.id).let { got ->
assertThat(got.name).isEqualTo(it.name)
assertThat(got.import).isEqualTo(import)
assertThat(got.importEntity).isEqualTo(import)
assertThat(got.id).isGreaterThan(0L)
}
}
Expand All @@ -44,7 +44,7 @@ class ImportFileRepositoryTest : AbstractSpringTest() {
builder.toString()
}

ImportFile(import = import, name = longName).let {
ImportFile(importEntity = import, name = longName).let {
assertThatExceptionOfType(ConstraintViolationException::class.java)
.isThrownBy {
importFileRepository.save(it)
Expand Down
6 changes: 3 additions & 3 deletions backend/data/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -246,8 +246,8 @@ ktlint {

hibernate {
enhancement {
enableDirtyTracking = false
enableAssociationManagement = false
enableExtendedEnhancement = false
// enableDirtyTracking = true
// enableAssociationManagement = false
// enableExtendedEnhancement = false
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class Import(
@ManyToOne(optional = false)
lateinit var author: UserAccount

@OneToMany(mappedBy = "import", orphanRemoval = true)
@OneToMany(mappedBy = "importEntity", orphanRemoval = true)
var files = mutableListOf<ImportFile>()

override var deletedAt: Date? = null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import io.tolgee.model.dataImport.issues.paramTypes.FileIssueParamType
import jakarta.persistence.Column
import jakarta.persistence.Entity
import jakarta.persistence.Index
import jakarta.persistence.JoinColumn
import jakarta.persistence.ManyToOne
import jakarta.persistence.OneToMany
import jakarta.persistence.Table
Expand All @@ -26,7 +27,10 @@ class ImportFile(
var name: String?,
@field:ManyToOne(optional = false)
@get:ManyToOne(optional = false)
val import: Import,
// It cannot be named "import", because with Hibernate 6.6 that fails to build
// It is probably some reserved keyword
@JoinColumn(name = "import_id")
val importEntity: Import,
) : StandardAuditModel() {
@OneToMany(mappedBy = "file", orphanRemoval = true)
var issues: MutableList<ImportFileIssue> = mutableListOf()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ interface ImportFileRepository : JpaRepository<ImportFile, Long> {
@Query(
"""
select f from ImportFile f
where f.import.project.id = :projectId
and f.import.author.id = :authorId
where f.importEntity.project.id = :projectId
and f.importEntity.author.id = :authorId
and f.id = :id
""",
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ interface ImportKeyRepository : JpaRepository<ImportKey, Long> {
select distinct ik from ImportKey ik
left join fetch ik.keyMeta km
join fetch ik.file if
join fetch if.import im where im.id = :importId
join fetch if.importEntity im where im.id = :importId
""",
)
fun findAllByImport(importId: Long): List<ImportKey>
Expand All @@ -27,6 +27,6 @@ interface ImportKeyRepository : JpaRepository<ImportKey, Long> {
@Query("""delete from ImportKey ik where ik.id in :ids""")
fun deleteByIdIn(ids: List<Long>)

@Query("""select iik.id from ImportKey iik join iik.file if where if.import = :import""")
@Query("""select iik.id from ImportKey iik join iik.file if where if.importEntity = :import""")
fun getAllIdsByImport(import: Import): List<Long>
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ LEFT JOIN il.existingLanguage el
"""
}

@Query("from ImportLanguage il join il.file if join if.import im where im.id = :importId")
@Query("from ImportLanguage il join il.file if join if.importEntity im where im.id = :importId")
fun findAllByImport(importId: Long): List<ImportLanguage>

@Modifying
Expand All @@ -60,7 +60,7 @@ LEFT JOIN il.existingLanguage el
@Query(
"""
$VIEW_BASE_QUERY
WHERE f.import.id = :importId
WHERE f.importEntity.id = :importId
$VIEW_GROUP_BY
order by il.id
""",
Expand All @@ -74,7 +74,7 @@ LEFT JOIN il.existingLanguage el
@Transactional
@Query(
"""delete from ImportLanguage l where l.file in
(select f from ImportFile f where f.import = :import)""",
(select f from ImportFile f where f.importEntity = :import)""",
)
fun deleteAllByImport(import: Import)

Expand All @@ -92,7 +92,7 @@ LEFT JOIN il.existingLanguage el
select distinct il.existingLanguage.id
from ImportLanguage il
join il.file if
where if.import.id = :importId
where if.importEntity.id = :importId
and il.existingLanguage.id is not null
""",
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ interface ImportRepository : JpaRepository<Import, Long> {

@Query(
"""
select distinct if.namespace from ImportFile if where if.import.id = :importId
select distinct if.namespace from ImportFile if where if.importEntity.id = :importId
""",
)
fun getAllNamespaces(importId: Long): Set<String?>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,12 @@ interface ImportTranslationRepository : JpaRepository<ImportTranslation, Long> {
from ImportTranslation it
left join it.conflict itc
join it.key ik
left join Namespace en on ik.file.namespace = en.name and en.project = ik.file.import.project
left join Key ek on it.key.name = ek.name and ek.project = it.key.file.import.project
left join Namespace en on ik.file.namespace = en.name and en.project = ik.file.importEntity.project
left join Key ek on it.key.name = ek.name and ek.project = it.key.file.importEntity.project
and (ek.namespace = en or (ek.namespace is null and en is null))
left join ik.keyMeta ikm
left join ek.keyMeta ekm
left join ImportSettings is on is.project = ik.file.import.project
left join ImportSettings is on is.project = ik.file.importEntity.project
where (itc.id is not null or :onlyConflicts = false)
and ((itc.id is not null and it.resolvedHash is null) or :onlyUnresolved = false)
and it.language.id = :languageId
Expand All @@ -76,7 +76,7 @@ interface ImportTranslationRepository : JpaRepository<ImportTranslation, Long> {
@Transactional
@Query(
"""delete from ImportTranslation it where it.key.id in
(select k.id from ImportKey k join k.file f where f.import = :import)""",
(select k.id from ImportKey k join k.file f where f.importEntity = :import)""",
)
@Modifying
fun deleteAllByImport(import: Import)
Expand All @@ -97,7 +97,7 @@ interface ImportTranslationRepository : JpaRepository<ImportTranslation, Long> {
join fetch it.language il
join il.file if
where if.needsParamConversion = true
and if.import.id = :importId
and if.importEntity.id = :importId
""",
)
fun findTranslationsForPlaceholderConversion(importId: Long): List<ImportTranslation>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ interface ImportFileIssueParamRepository : JpaRepository<ImportFileIssueParam, L
@Modifying
@Query(
"""delete from ImportFileIssueParam ifip where ifip.issue in
(select ifi from ifip.issue ifi join ifi.file if where if.import = :import)
(select ifi from ifip.issue ifi join ifi.file if where if.importEntity = :import)
""",
)
fun deleteAllByImport(import: Import)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ interface ImportFileIssueRepository : JpaRepository<ImportFileIssue, Long> {
@Transactional
@Query(
"""delete from ImportFileIssue ifi where ifi.file in
(select f from ImportFile f where f.import = :import)""",
(select f from ImportFile f where f.importEntity = :import)""",
)
@Modifying
fun deleteAllByImport(import: Import)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ class ImportService(
if (importLanguage.existingLanguage == existingLanguage) {
return
}
val import = importLanguage.file.import
val import = importLanguage.file.importEntity
Sentry.addBreadcrumb("Import ID: ${import.id}")
val dataManager = ImportDataManager(applicationContext, import)
val oldExistingLanguage = importLanguage.existingLanguage
Expand All @@ -221,7 +221,7 @@ class ImportService(
namespace: String?,
) {
val file = findFile(projectId, authorId, fileId) ?: throw NotFoundException()
val import = file.import
val import = file.importEntity
Sentry.addBreadcrumb("Import ID: ${import.id}")
val dataManager = ImportDataManager(applicationContext, import)
file.namespace = getSafeNamespace(namespace)
Expand Down Expand Up @@ -290,7 +290,7 @@ class ImportService(
left join fetch ik.keyMeta ikm
left join fetch ikm.comments ikc
join ik.file if
where if.import = :import
where if.importEntity = :import
""",
)
.setParameter("import", import)
Expand Down Expand Up @@ -394,10 +394,10 @@ class ImportService(

@Transactional
fun deleteLanguage(language: ImportLanguage) {
val import = language.file.import
val import = language.file.importEntity
this.importTranslationRepository.deleteAllByLanguage(language)
this.importLanguageRepository.delete(language)
if (this.findLanguages(import = language.file.import).isEmpty()) {
if (this.findLanguages(import = language.file.importEntity).isEmpty()) {
deleteImport(import)
return
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class KeyMetaService(
join fetch ikm.importKey ik
left join fetch ikm.comments ikc
join ik.file if
where if.import = :import
where if.importEntity = :import
""",
)
.setParameter("import", import)
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ kotlinVersion=2.0.20
springBootVersion=3.3.3
springDocVersion=2.3.0
jjwtVersion=0.11.2
hibernateVersion=6.5.2.Final
hibernateVersion=6.6.5.Final
amazonAwsSdkVersion=2.20.8
springDependencyManagementVersion=1.0.11.RELEASE
org.gradle.jvmargs=-Xmx6g -Dkotlin.daemon.jvm.options=-Xmx6g
Expand Down
Loading