Boilerplate-Code für das Einbinden von Hibernate ORM und dessen Konfiguration über projektspezifische Overrides aus z.B. einer config.yaml
<?xml version = "1.0" encoding = "utf-8"?>
<!DOCTYPE hibernate-configuration SYSTEM "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.dialect">org.hibernate.dialect.PostgreSQL9Dialect</property>
<property name="hibernate.connection.driver_class">org.postgresql.Driver</property>
<property name="hibernate.jdbc.time_zone">UTC</property>
<property name="hibernate.connection.url">See config.yaml</property>
<property name="hibernate.connection.username">See config.yaml</property>
<property name="hibernate.connection.password">See config.yaml</property>
<property name="show_sql">false</property>
<mapping class="com.timtrense.project.domain.DomainclassXY"/>
</session-factory>
</hibernate-configuration>
private static EntityManager openPersistence( @lombok.NonNull com.timtrense.project.Configuration configuration ) {
org.hibernate.cfg.Configuration configObj = new org.hibernate.cfg.Configuration();
configObj.configure( "hibernate.cfg.xml" );
configObj.setProperty( "hibernate.connection.url", configuration.getDatabase().getUrl() );
configObj.setProperty( "hibernate.connection.username", configuration.getDatabase().getUsername() );
configObj.setProperty( "hibernate.connection.password", configuration.getDatabase().getPassword() );
return configObj.buildSessionFactory().createEntityManager();
}