use of org.hibernate.mapping.Collection in project hibernate-orm by hibernate.
the class FieldAccessedNestedEmbeddableMetadataTest method testEnumTypeInterpretation.
@Test
@FailureExpected(jiraKey = "HHH-9089")
public void testEnumTypeInterpretation() {
StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().build();
try {
final Metadata metadata = new MetadataSources(ssr).addAnnotatedClass(Customer.class).buildMetadata();
PersistentClass classMetadata = metadata.getEntityBinding(Customer.class.getName());
Property investmentsProperty = classMetadata.getProperty("investments");
Collection investmentsValue = (Collection) investmentsProperty.getValue();
Component investmentMetadata = (Component) investmentsValue.getElement();
Value descriptionValue = investmentMetadata.getProperty("description").getValue();
assertEquals(1, descriptionValue.getColumnSpan());
Column selectable = (Column) descriptionValue.getColumnIterator().next();
assertEquals(500, selectable.getLength());
Component amountMetadata = (Component) investmentMetadata.getProperty("amount").getValue();
SimpleValue currencyMetadata = (SimpleValue) amountMetadata.getProperty("currency").getValue();
CustomType currencyType = (CustomType) currencyMetadata.getType();
int[] currencySqlTypes = currencyType.sqlTypes(metadata);
assertEquals(1, currencySqlTypes.length);
assertJdbcTypeCode(Types.VARCHAR, currencySqlTypes[0]);
} finally {
StandardServiceRegistryBuilder.destroy(ssr);
}
}
use of org.hibernate.mapping.Collection in project hibernate-orm by hibernate.
the class FullyQualifiedEntityNameNamingStrategyTest method testManyToManyForeignKeys.
@Test
@TestForIssue(jiraKey = "HHH-9327")
public void testManyToManyForeignKeys() {
final Collection ownerCollectionMapping = metadata.getCollectionBinding(Category.class.getName() + "." + "items");
final String expectedOwnerFK = transformEntityName(Category.class.getName()) + "_id";
final String expectedInverseFK = transformEntityName(Item.class.getName()) + "_items_id";
boolean ownerFKFound = false;
boolean inverseFKFound = false;
for (Iterator it = ownerCollectionMapping.getCollectionTable().getForeignKeyIterator(); it.hasNext(); ) {
final String fkColumnName = ((ForeignKey) it.next()).getColumn(0).getName();
if (expectedOwnerFK.equals(fkColumnName)) {
ownerFKFound = true;
} else if (expectedInverseFK.equals(fkColumnName)) {
inverseFKFound = true;
}
}
assertTrue(ownerFKFound);
assertTrue(inverseFKFound);
}
use of org.hibernate.mapping.Collection in project hibernate-orm by hibernate.
the class FullyQualifiedEntityNameNamingStrategyTest method testElementCollectionTable.
@Test
@TestForIssue(jiraKey = "HHH-9327")
public void testElementCollectionTable() {
final Collection collectionMapping = metadata.getCollectionBinding(Workflow.class.getName() + ".localized");
final String expectedTableName = transformEntityName(Workflow.class.getName()) + "_localized";
assertEquals(expectedTableName, collectionMapping.getCollectionTable().getName());
}
use of org.hibernate.mapping.Collection in project hibernate-orm by hibernate.
the class CollectionJoinTableNamingTest method testCollectionJoinTableNamingLegacyHbmStrategy.
@Test
@TestForIssue(jiraKey = "HHH-9908")
public void testCollectionJoinTableNamingLegacyHbmStrategy() {
final MetadataSources metadataSources = new MetadataSources();
try {
metadataSources.addAnnotatedClass(Input.class);
metadataSources.addAnnotatedClass(Ptx.class);
final Metadata metadata = metadataSources.getMetadataBuilder().applyImplicitNamingStrategy(ImplicitNamingStrategyLegacyHbmImpl.INSTANCE).build();
Collection inputs1Mapping = metadata.getCollectionBinding(Ptx.class.getName() + ".inputs1");
assertEquals("ptx_inputs1", inputs1Mapping.getCollectionTable().getName());
Collection inputs2Mapping = metadata.getCollectionBinding(Ptx.class.getName() + ".inputs2");
assertEquals("ptx_inputs2", inputs2Mapping.getCollectionTable().getName());
} finally {
ServiceRegistry metaServiceRegistry = metadataSources.getServiceRegistry();
if (metaServiceRegistry instanceof BootstrapServiceRegistry) {
BootstrapServiceRegistryBuilder.destroy(metaServiceRegistry);
}
}
}
use of org.hibernate.mapping.Collection 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());
}
}
Aggregations