Skip to content
Anjunar/ DOCS

Runtime bootstrap

Build the metadata; the runtime discovers annotated translation fields automatically.

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 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.

Discovery

Annotation-only mapping

Declare translated properties only through annotations. openSession discovers every @Localized entity, @Translation member and JPA converter from Hibernate metadata automatically.

Get a metadata-derived editor handle

The annotations fully define the mapping. Request a handle only when an editor needs exact inactive locales.

scala
import com.anjunar.hibernatei18n.runtime.HibernateI18n val translations = HibernateI18n.translations(factory, classOf[Page])
scala
val session = HibernateI18n.openSession(factory, "de") try // Use this Session for one content locale. () finally session.close()