Skip to content
Anjunar/ DOCS

Runtime bootstrap

Build the metadata and install every translated field bridge before opening a localized Session.

Setup

Build the runtime metadata

Create the registry with HibernateI18n so the mapping generator and metadata finalizer are installed. Provide a PostgreSQL DataSource and the annotated Page from the mapping guide.

Registry and schema preparation

Use the DDL manager as the schema owner. Migrate the complete metadata before building the factory and keep Hibernate schema generation disabled.

scala
import com.anjunar.hibernatei18n.runtime.HibernateI18n import com.anjunar.hibernateddl.integration.HibernateSchemaMigration import org.hibernate.boot.MetadataSources val registry = HibernateI18n.registryBuilder() .applySetting("hibernate.connection.datasource", dataSource) .applySetting("hibernate.cache.use_query_cache", "false") .applySetting("hibernate.hbm2ddl.auto", "none") .build() val metadata = new MetadataSources(registry) .addAnnotatedClass(classOf[Page]) .buildMetadata() HibernateSchemaMigration.migrate(metadata, dataSource) val factory = metadata.buildSessionFactory()
Text-column upgrade

The upgrade helper requires an auto-commit PostgreSQL connection. It widens existing generated varchar columns to text, preserves values, and leaves missing tables to schema creation.

Bridge

Install every localized entity

Install once per mapped @Localized entity before the first localized Session. The field list must contain every translated member, and each reader must read its named property.

Register the title bridge

Keep the returned handle and field object for editor access. A missing entity bridge or a miswired reader is rejected.

scala
import com.anjunar.hibernatei18n.runtime.{TranslationField, HibernateI18n} val titleField = TranslationField.string[Page]("title", _.title) val translations = HibernateI18n.install( factory, classOf[Page], _.id, Seq(titleField))
scala
val session = HibernateI18n.openSession(factory, "de") try // Use this Session for one content locale. () finally session.close()