use of org.hibernate.tool.hbm2ddl.SchemaExport in project hibernate-orm by hibernate.
the class SQLServer2008NVarCharTypeTest method createSchemaExport.
private SchemaExport createSchemaExport(Class[] annotatedClasses) {
final MetadataSources metadataSources = new MetadataSources(ssr);
for (Class c : annotatedClasses) {
metadataSources.addAnnotatedClass(c);
}
metadata = (MetadataImplementor) metadataSources.buildMetadata();
metadata.validate();
SchemaExport schemaExport = new SchemaExport();
schemaExport.setHaltOnError(true).setFormat(false);
return schemaExport;
}
use of org.hibernate.tool.hbm2ddl.SchemaExport in project hibernate-orm by hibernate.
the class DisabledForeignKeyTest method basicTests.
@Test
@TestForIssue(jiraKey = "HHH-9704")
public void basicTests() {
StandardServiceRegistryBuilder registryBuilder = new StandardServiceRegistryBuilder();
StandardServiceRegistry standardRegistry = registryBuilder.build();
try {
final MetadataSources sources = new MetadataSources(standardRegistry);
sources.addAnnotatedClass(ManyToManyOwner.class);
sources.addAnnotatedClass(ManyToManyTarget.class);
final MetadataImplementor metadata = (MetadataImplementor) sources.buildMetadata();
metadata.validate();
new SchemaExport().execute(EnumSet.of(TargetType.STDOUT), SchemaExport.Action.CREATE, metadata);
int fkCount = 0;
for (Table table : metadata.collectTableMappings()) {
for (Map.Entry<ForeignKeyKey, ForeignKey> entry : table.getForeignKeys().entrySet()) {
assertFalse("Creation for ForeignKey [" + entry.getKey() + "] was not disabled", entry.getValue().isCreationEnabled());
fkCount++;
}
}
// ultimately I want to actually create the ForeignKet reference, but simply disable its creation
// via ForeignKet#disableCreation()
assertEquals("Was expecting 4 FKs", 0, fkCount);
} finally {
StandardServiceRegistryBuilder.destroy(standardRegistry);
}
}
use of org.hibernate.tool.hbm2ddl.SchemaExport in project hibernate-orm by hibernate.
the class CollectionJoinTableNamingTest method assertSameTableUsed.
private void assertSameTableUsed(Metadata metadata) {
Collection inputs1Mapping = metadata.getCollectionBinding(Ptx.class.getName() + ".inputs1");
assertEquals("ptx_input", inputs1Mapping.getCollectionTable().getName());
Collection inputs2Mapping = metadata.getCollectionBinding(Ptx.class.getName() + ".inputs2");
assertEquals("ptx_input", inputs2Mapping.getCollectionTable().getName());
assertSame(inputs1Mapping.getCollectionTable(), inputs2Mapping.getCollectionTable());
// NOTE : here so that tester can more easily see the produced table. It is only dumped to stdout
new SchemaExport().create(EnumSet.of(TargetType.STDOUT), metadata);
for (int i = 0; i < inputs1Mapping.getCollectionTable().getColumnSpan(); i++) {
final Column column = inputs1Mapping.getCollectionTable().getColumn(i);
// this, coupled with JPA saying the 2 collections implicitly map to the same table,
// is the crux of the problem: all columns are null, so we effectively can never
// insert rows into it.
assertFalse(column.isNullable());
}
}
use of org.hibernate.tool.hbm2ddl.SchemaExport in project hibernate-orm by hibernate.
the class ColumnNamesTest method setUp.
@Before
public void setUp() throws IOException {
ssr = new StandardServiceRegistryBuilder().applySetting(AvailableSettings.KEYWORD_AUTO_QUOTING_ENABLED, "true").applySetting(AvailableSettings.HBM2DDL_JDBC_METADATA_EXTRACTOR_STRATEGY, jdbcMetadataExtractorStrategy).build();
output = File.createTempFile("update_script", ".sql");
output.deleteOnExit();
metadata = new MetadataSources(ssr).addAnnotatedClass(Employee.class).buildMetadata();
new SchemaExport().create(EnumSet.of(TargetType.DATABASE), metadata);
}
use of org.hibernate.tool.hbm2ddl.SchemaExport in project hibernate-orm by hibernate.
the class MigrationTest method testSimpleColumnAddition.
@Test
public void testSimpleColumnAddition() {
String resource1 = "org/hibernate/test/schemaupdate/1_Version.hbm.xml";
String resource2 = "org/hibernate/test/schemaupdate/2_Version.hbm.xml";
MetadataImplementor v1metadata = (MetadataImplementor) new MetadataSources(serviceRegistry).addResource(resource1).buildMetadata();
new SchemaExport().drop(EnumSet.of(TargetType.DATABASE), v1metadata);
final SchemaUpdate v1schemaUpdate = new SchemaUpdate();
v1schemaUpdate.execute(EnumSet.of(TargetType.DATABASE, TargetType.STDOUT), v1metadata);
assertEquals(0, v1schemaUpdate.getExceptions().size());
MetadataImplementor v2metadata = (MetadataImplementor) new MetadataSources(serviceRegistry).addResource(resource2).buildMetadata();
final SchemaUpdate v2schemaUpdate = new SchemaUpdate();
v2schemaUpdate.execute(EnumSet.of(TargetType.DATABASE, TargetType.STDOUT), v2metadata);
assertEquals(0, v2schemaUpdate.getExceptions().size());
new SchemaExport().drop(EnumSet.of(TargetType.DATABASE), v2metadata);
}
Aggregations