use of org.hibernate.boot.Metadata in project hibernate-orm by hibernate.
the class NullablePrimaryKeyTest method testGeneratedSql.
@Test
@SuppressWarnings("unchecked")
public void testGeneratedSql() {
Map settings = new HashMap();
settings.putAll(Environment.getProperties());
settings.put(AvailableSettings.DIALECT, SQLServerDialect.class.getName());
ServiceRegistry serviceRegistry = ServiceRegistryBuilder.buildServiceRegistry(settings);
try {
MetadataSources ms = new MetadataSources(serviceRegistry);
ms.addAnnotatedClass(Address.class);
ms.addAnnotatedClass(Person.class);
final Metadata metadata = ms.buildMetadata();
final List<String> commands = new SchemaCreatorImpl(serviceRegistry).generateCreationCommands(metadata, false);
for (String s : commands) {
log.debug(s);
}
String expectedMappingTableSql = "create table personAddress (address_id numeric(19,0), " + "person_id numeric(19,0) not null, primary key (person_id))";
Assert.assertEquals("Wrong SQL", expectedMappingTableSql, commands.get(2));
} catch (Exception e) {
Assert.fail(e.getMessage());
} finally {
ServiceRegistryBuilder.destroy(serviceRegistry);
}
}
use of org.hibernate.boot.Metadata 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.Metadata in project hibernate-orm by hibernate.
the class MySQLDropConstraintThrowsExceptionTest method setUp.
@Before
public void setUp() {
final StandardServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder().enableAutoClose().applySetting(AvailableSettings.HBM2DDL_AUTO, "drop").build();
SessionFactoryImplementor sessionFactory = null;
try {
final Metadata metadata = new MetadataSources(serviceRegistry).addAnnotatedClass(Customer.class).buildMetadata();
sessionFactory = (SessionFactoryImplementor) metadata.buildSessionFactory();
} finally {
if (sessionFactory != null) {
sessionFactory.close();
}
StandardServiceRegistryBuilder.destroy(serviceRegistry);
}
}
use of org.hibernate.boot.Metadata in project hibernate-orm by hibernate.
the class MySQLDropConstraintThrowsExceptionTest method tearDown.
@After
public void tearDown() {
final StandardServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder().enableAutoClose().applySetting(AvailableSettings.HBM2DDL_AUTO, "drop").build();
SessionFactoryImplementor sessionFactory = null;
try {
final Metadata metadata = new MetadataSources(serviceRegistry).addAnnotatedClass(Customer.class).buildMetadata();
sessionFactory = (SessionFactoryImplementor) metadata.buildSessionFactory();
} finally {
if (sessionFactory != null) {
sessionFactory.close();
}
StandardServiceRegistryBuilder.destroy(serviceRegistry);
}
}
use of org.hibernate.boot.Metadata in project hibernate-orm by hibernate.
the class MySQLDropConstraintThrowsExceptionTest method testEnumTypeInterpretation.
@Test
public void testEnumTypeInterpretation() {
final PreparedStatementSpyConnectionProvider connectionProvider = new PreparedStatementSpyConnectionProvider();
final StandardServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder().enableAutoClose().applySetting(AvailableSettings.HBM2DDL_AUTO, "update").applySetting(AvailableSettings.CONNECTION_PROVIDER, connectionProvider).build();
SessionFactory sessionFactory = null;
try {
final Metadata metadata = new MetadataSources(serviceRegistry).addAnnotatedClass(Customer.class).buildMetadata();
sessionFactory = metadata.buildSessionFactory();
List<String> alterStatements = connectionProvider.getExecuteStatements().stream().filter(sql -> sql.toLowerCase().contains("alter ")).map(String::trim).collect(Collectors.toList());
assertTrue(alterStatements.get(0).matches("alter table CUSTOMER\\s+drop index .*?"));
assertTrue(alterStatements.get(1).matches("alter table CUSTOMER\\s+add constraint .*? unique \\(CUSTOMER_ID\\)"));
} finally {
if (sessionFactory != null) {
sessionFactory.close();
}
StandardServiceRegistryBuilder.destroy(serviceRegistry);
}
}
Aggregations