HHH-18003 - Create a PersistenceUnitDescriptor wrapper around JPA 3.2 PersistenceConfiguration

This commit is contained in:
Steve Ebersole 2024-04-24 07:52:24 -05:00
parent 3822aefec9
commit c9ad1aee4b
1 changed files with 36 additions and 0 deletions

View File

@ -0,0 +1,36 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
* See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html.
*/
package org.hibernate.orm.test.jpa.boot;
import org.hibernate.cfg.SchemaToolingSettings;
import org.hibernate.jpa.HibernatePersistenceProvider;
import org.hibernate.tool.schema.Action;
import org.hibernate.testing.orm.domain.StandardDomainModel;
import org.junit.jupiter.api.Test;
import jakarta.persistence.EntityManagerFactory;
import jakarta.persistence.PersistenceConfiguration;
/**
* @author Steve Ebersole
*/
public class PersistenceConfigurationTests {
@Test
void test1() {
final PersistenceConfiguration configuration = new PersistenceConfiguration( "tst1" )
.property( SchemaToolingSettings.JAKARTA_HBM2DDL_DATABASE_ACTION, Action.CREATE );
for ( Class<?> annotatedClass : StandardDomainModel.RETAIL.getDescriptor().getAnnotatedClasses() ) {
configuration.managedClass( annotatedClass );
}
try (EntityManagerFactory entityManagerFactory = new HibernatePersistenceProvider().createEntityManagerFactory( configuration )) {
entityManagerFactory.runInTransaction( entityManager -> {
entityManager.createQuery( "from Order" ).getResultList();
} );
}
}
}