use of org.hibernate.boot.Metadata in project hibernate-orm by hibernate.
the class ParameterizedAttributeConverterParameterTypeTest method testNestedTypeParameterAutoApplication.
@Test
@TestForIssue(jiraKey = "HHH-10050")
public void testNestedTypeParameterAutoApplication() {
final Metadata metadata = new MetadataSources(ssr).addAnnotatedClass(SampleEntity.class).getMetadataBuilder().applyAttributeConverter(IntegerListConverter.class).applyAttributeConverter(StringListConverter.class).build();
// lets make sure the auto-apply converters were applied properly...
PersistentClass pc = metadata.getEntityBinding(SampleEntity.class.getName());
{
Property prop = pc.getProperty("someStrings");
AttributeConverterTypeAdapter type = assertTyping(AttributeConverterTypeAdapter.class, prop.getType());
assertTrue(StringListConverter.class.isAssignableFrom(type.getAttributeConverter().getConverterJavaTypeDescriptor().getJavaType()));
}
{
Property prop = pc.getProperty("someIntegers");
AttributeConverterTypeAdapter type = assertTyping(AttributeConverterTypeAdapter.class, prop.getType());
assertTrue(IntegerListConverter.class.isAssignableFrom(type.getAttributeConverter().getConverterJavaTypeDescriptor().getJavaType()));
}
}
use of org.hibernate.boot.Metadata in project hibernate-orm by hibernate.
the class NonRootEntityWithCacheAnnotationTest method testCacheOnNonRootEntity.
@Test
public void testCacheOnNonRootEntity() {
Map settings = new HashMap();
settings.put(Environment.CACHE_REGION_FACTORY, CachingRegionFactory.class.getName());
settings.put(AvailableSettings.JPA_SHARED_CACHE_MODE, SharedCacheMode.ENABLE_SELECTIVE);
ServiceRegistryImplementor serviceRegistry = (ServiceRegistryImplementor) new StandardServiceRegistryBuilder().applySettings(settings).build();
Triggerable triggerable = logInspection.watchForLogMessages("HHH000482");
Metadata metadata = new MetadataSources(serviceRegistry).addAnnotatedClass(ABase.class).addAnnotatedClass(AEntity.class).buildMetadata();
assertTrue(triggerable.wasTriggered());
assertFalse(metadata.getEntityBinding(AEntity.class.getName()).isCached());
serviceRegistry.destroy();
}
use of org.hibernate.boot.Metadata in project hibernate-orm by hibernate.
the class NonRootEntityWithCacheableAnnotationTest method testCacheableOnNonRootEntity.
@Test
public void testCacheableOnNonRootEntity() {
Map settings = new HashMap();
settings.put(Environment.CACHE_REGION_FACTORY, CachingRegionFactory.class.getName());
settings.put(AvailableSettings.DEFAULT_CACHE_CONCURRENCY_STRATEGY, "read-write");
settings.put(AvailableSettings.JPA_SHARED_CACHE_MODE, SharedCacheMode.ENABLE_SELECTIVE);
ServiceRegistryImplementor serviceRegistry = (ServiceRegistryImplementor) new StandardServiceRegistryBuilder().applySettings(settings).build();
Triggerable triggerable = logInspection.watchForLogMessages("HHH000482");
Metadata metadata = new MetadataSources(serviceRegistry).addAnnotatedClass(ABase.class).addAnnotatedClass(AEntity.class).buildMetadata();
assertFalse(metadata.getEntityBinding(ABase.class.getName()).isCached());
assertTrue(metadata.getEntityBinding(AEntity.class.getName()).isCached());
assertFalse(triggerable.wasTriggered());
serviceRegistry.destroy();
}
use of org.hibernate.boot.Metadata in project hibernate-orm by hibernate.
the class GetAndIsVariantGetterTest method testInstanceStaticConflict.
@Test
@TestForIssue(jiraKey = "HHH-12046")
public void testInstanceStaticConflict() {
Metadata metadata = new MetadataSources(ssr).addAnnotatedClass(InstanceStaticEntity.class).buildMetadata();
assertNotNull(metadata.getEntityBinding(InstanceStaticEntity.class.getName()).getIdentifier());
assertNotNull(metadata.getEntityBinding(InstanceStaticEntity.class.getName()).getIdentifierProperty());
assertTrue(metadata.getEntityBinding(InstanceStaticEntity.class.getName()).hasProperty("foo"));
ReflectHelper.findGetterMethod(InstanceStaticEntity.class, "foo");
}
use of org.hibernate.boot.Metadata in project hibernate-orm by hibernate.
the class TransactionsTest method jdbc.
@Test
public void jdbc() {
// tag::transactions-api-jdbc-example[]
StandardServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder().applySetting(AvailableSettings.TRANSACTION_COORDINATOR_STRATEGY, "jdbc").build();
Metadata metadata = new MetadataSources(serviceRegistry).addAnnotatedClass(Customer.class).getMetadataBuilder().build();
SessionFactory sessionFactory = metadata.getSessionFactoryBuilder().build();
Session session = sessionFactory.openSession();
try {
// calls Connection#setAutoCommit( false ) to
// signal start of transaction
session.getTransaction().begin();
session.createQuery("UPDATE customer set NAME = 'Sir. '||NAME").executeUpdate();
// calls Connection#commit(), if an error
// happens we attempt a rollback
session.getTransaction().commit();
} catch (Exception e) {
// where the exception happened
if (session.getTransaction().getStatus() == TransactionStatus.ACTIVE || session.getTransaction().getStatus() == TransactionStatus.MARKED_ROLLBACK) {
session.getTransaction().rollback();
}
// handle the underlying error
} finally {
session.close();
sessionFactory.close();
}
// end::transactions-api-jdbc-example[]
}
Aggregations