use of org.hibernate.boot.spi.MetadataImplementor in project hibernate-orm by hibernate.
the class InheritedAttributeOverridingTest method testInheritedAttributeOverridingEntity.
@Test
@TestForIssue(jiraKey = "HHH-9485")
public void testInheritedAttributeOverridingEntity() {
Metadata metadata = new MetadataSources(standardServiceRegistry).addAnnotatedClass(C.class).addAnnotatedClass(D.class).buildMetadata();
((MetadataImplementor) metadata).validate();
}
use of org.hibernate.boot.spi.MetadataImplementor in project hibernate-orm by hibernate.
the class DefaultCacheConcurrencyPropertyTest method testExplicitDefault.
@Test
@TestForIssue(jiraKey = "HHH-9763")
@FailureExpected(jiraKey = "HHH-9763")
public void testExplicitDefault() {
final StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().applySetting(AvailableSettings.DEFAULT_CACHE_CONCURRENCY_STRATEGY, "read-only").build();
try {
assertEquals("read-only", ssr.getService(ConfigurationService.class).getSettings().get(AvailableSettings.DEFAULT_CACHE_CONCURRENCY_STRATEGY));
final MetadataImplementor metadata = (MetadataImplementor) new MetadataSources(ssr).addAnnotatedClass(TheEntity.class).buildMetadata();
assertEquals(AccessType.READ_ONLY, metadata.getMetadataBuildingOptions().getMappingDefaults().getImplicitCacheAccessType());
final SessionFactoryImplementor sf = (SessionFactoryImplementor) metadata.buildSessionFactory();
try {
final EntityPersister persister = sf.getMetamodel().entityPersister(TheEntity.class.getName());
assertNotNull(persister.getCacheAccessStrategy());
} finally {
sf.close();
}
} finally {
StandardServiceRegistryBuilder.destroy(ssr);
}
}
use of org.hibernate.boot.spi.MetadataImplementor in project hibernate-orm by hibernate.
the class AttributeConverterTest method testBasicOperation.
@Test
public void testBasicOperation() {
final StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().build();
try {
MetadataImplementor metadata = (MetadataImplementor) new MetadataSources(ssr).buildMetadata();
SimpleValue simpleValue = new SimpleValue(metadata);
simpleValue.setJpaAttributeConverterDescriptor(new AttributeConverterDescriptorNonAutoApplicableImpl(new StringClobConverter()));
simpleValue.setTypeUsingReflection(IrrelevantEntity.class.getName(), "name");
Type type = simpleValue.getType();
assertNotNull(type);
if (!AttributeConverterTypeAdapter.class.isInstance(type)) {
fail("AttributeConverter not applied");
}
AbstractStandardBasicType basicType = assertTyping(AbstractStandardBasicType.class, type);
assertSame(StringTypeDescriptor.INSTANCE, basicType.getJavaTypeDescriptor());
assertEquals(Types.CLOB, basicType.getSqlTypeDescriptor().getSqlType());
} finally {
StandardServiceRegistryBuilder.destroy(ssr);
}
}
use of org.hibernate.boot.spi.MetadataImplementor in project hibernate-orm by hibernate.
the class AttributeConverterTest method testEnumConverter.
@Test
@TestForIssue(jiraKey = "HHH-8866")
public void testEnumConverter() {
final StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().applySetting(AvailableSettings.HBM2DDL_AUTO, "create-drop").build();
try {
MetadataImplementor metadata = (MetadataImplementor) new MetadataSources(ssr).addAnnotatedClass(EntityWithConvertibleField.class).getMetadataBuilder().applyAttributeConverter(ConvertibleEnumConverter.class, true).build();
// first lets validate that the converter was applied...
PersistentClass tester = metadata.getEntityBinding(EntityWithConvertibleField.class.getName());
Property nameProp = tester.getProperty("convertibleEnum");
SimpleValue nameValue = (SimpleValue) nameProp.getValue();
Type type = nameValue.getType();
assertNotNull(type);
assertTyping(BasicType.class, type);
if (!AttributeConverterTypeAdapter.class.isInstance(type)) {
fail("AttributeConverter not applied");
}
AbstractStandardBasicType basicType = assertTyping(AbstractStandardBasicType.class, type);
assertTyping(EnumJavaTypeDescriptor.class, basicType.getJavaTypeDescriptor());
assertEquals(Types.VARCHAR, basicType.getSqlTypeDescriptor().getSqlType());
// then lets build the SF and verify its use...
final SessionFactory sf = metadata.buildSessionFactory();
try {
Session s = sf.openSession();
s.getTransaction().begin();
EntityWithConvertibleField entity = new EntityWithConvertibleField();
entity.setId("ID");
entity.setConvertibleEnum(ConvertibleEnum.VALUE);
String entityID = entity.getId();
s.persist(entity);
s.getTransaction().commit();
s.close();
s = sf.openSession();
s.beginTransaction();
entity = (EntityWithConvertibleField) s.load(EntityWithConvertibleField.class, entityID);
assertEquals(ConvertibleEnum.VALUE, entity.getConvertibleEnum());
s.getTransaction().commit();
s.close();
JavaConstantNode javaConstantNode = new JavaConstantNode();
javaConstantNode.setExpectedType(type);
javaConstantNode.setSessionFactory((SessionFactoryImplementor) sf);
javaConstantNode.setText("org.hibernate.test.converter.AttributeConverterTest$ConvertibleEnum.VALUE");
final String outcome = javaConstantNode.getRenderText((SessionFactoryImplementor) sf);
assertEquals("'VALUE'", outcome);
s = sf.openSession();
s.beginTransaction();
s.createQuery("FROM EntityWithConvertibleField e where e.convertibleEnum = org.hibernate.test.converter.AttributeConverterTest$ConvertibleEnum.VALUE").list();
s.getTransaction().commit();
s.close();
s = sf.openSession();
s.beginTransaction();
s.delete(entity);
s.getTransaction().commit();
s.close();
} finally {
try {
sf.close();
} catch (Exception ignore) {
}
}
} finally {
StandardServiceRegistryBuilder.destroy(ssr);
}
}
use of org.hibernate.boot.spi.MetadataImplementor in project hibernate-orm by hibernate.
the class CollectionCompositeElementExplicitConversionTest method testCollectionOfEmbeddablesWithConvertedAttributes.
@Test
public void testCollectionOfEmbeddablesWithConvertedAttributes() throws Exception {
final MetadataImplementor metadata = (MetadataImplementor) new MetadataSources(ssr).addAnnotatedClass(Disguise.class).addAnnotatedClass(Traits.class).buildMetadata();
metadata.validate();
final PersistentClass entityBinding = metadata.getEntityBinding(Disguise.class.getName());
// first check the singular composite...
final Property singularTraitsProperty = entityBinding.getProperty("singularTraits");
checkComposite((Component) singularTraitsProperty.getValue());
// then check the plural composite...
final Property pluralTraitsProperty = entityBinding.getProperty("pluralTraits");
checkComposite((Component) ((org.hibernate.mapping.Set) pluralTraitsProperty.getValue()).getElement());
}
Aggregations