Skip to content
Anjunar/ DOCS

Entity mapping

Declare translated fields and converted values while keeping their ordinary domain types.

Mapping

Annotate the owning entity

@Localized declares the fallback policy; @Translation marks each property whose value belongs to a locale row. The parent has no column for that translated value.

A translated String

Use a UUID ID and consistent field access. A named translation column uses @Translation(column = ...).

scala
import com.anjunar.hibernatei18n.annotation.{Localized, Translation} import com.anjunar.hibernateddl.hibernate.annotation.SchemaId import jakarta.persistence.{Entity, Id, Table} import java.util.UUID import scala.compiletime.uninitialized @Entity @Table(name = "page") @SchemaId("7f3a9c21") @Localized(defaultLocale = "en", fallbackLocale = "en") class Page: @Id @SchemaId("0a1b2c3d") var id: UUID = uninitialized @Translation @SchemaId("f34e45b6") var title: String = uninitialized
scala
@Translation(column = "display_title") var title: String = uninitialized
Field or getter access

JavaBean getter access is supported too. Keep the ID and translated members on the same access path; mixed access and @Column directly on @Translation fail at bootstrap.

Conversion

Keep a typed value

A converted translated property must use a String database representation. Its TranslationField encoder and decoder must match the JPA converter.

A converted Markdown field

Add this member to Page with your Markdown type and converter, then install both fields together.

scala
@Translation @SchemaId("cdef1234") @jakarta.persistence.Convert(converter = classOf[MarkdownConverter]) var content: Markdown = uninitialized val titleField = TranslationField.string[Page]("title", _.title) val contentField = TranslationField.converted[Page, Markdown]( "content", _.content, _.source, Markdown.apply) val translations = HibernateI18n.install( factory, classOf[Page], _.id, Seq(titleField, contentField))