use of org.hibernate.mapping.Collection in project hibernate-orm by hibernate.
the class ElementCollectionTests method testSimpleConvertUsage.
@Test
public void testSimpleConvertUsage() throws MalformedURLException {
// first some assertions of the metamodel
PersistentClass entityBinding = metadata().getEntityBinding(TheEntity.class.getName());
assertNotNull(entityBinding);
Property setAttributeBinding = entityBinding.getProperty("set");
Collection setBinding = (Collection) setAttributeBinding.getValue();
assertTyping(AttributeConverterTypeAdapter.class, setBinding.getElement().getType());
Property mapAttributeBinding = entityBinding.getProperty("map");
IndexedCollection mapBinding = (IndexedCollection) mapAttributeBinding.getValue();
assertTyping(AttributeConverterTypeAdapter.class, mapBinding.getIndex().getType());
assertTyping(AttributeConverterTypeAdapter.class, mapBinding.getElement().getType());
// now lets try to use the model, integration-testing-style!
TheEntity entity = new TheEntity(1);
Session s = openSession();
s.beginTransaction();
s.save(entity);
s.getTransaction().commit();
s.close();
s = openSession();
s.beginTransaction();
TheEntity retrieved = (TheEntity) s.load(TheEntity.class, 1);
assertEquals(1, retrieved.getSet().size());
assertEquals(new ValueType("set_value"), retrieved.getSet().iterator().next());
assertEquals(1, retrieved.getMap().size());
assertEquals(new ValueType("map_value"), retrieved.getMap().get(new ValueType("map_key")));
s.delete(retrieved);
s.getTransaction().commit();
s.close();
}
use of org.hibernate.mapping.Collection in project hibernate-orm by hibernate.
the class NestedEmbeddableMetadataTest method testEnumTypeInterpretation.
@Test
public void testEnumTypeInterpretation() {
final StandardServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder().enableAutoClose().applySetting(AvailableSettings.HBM2DDL_AUTO, "create-drop").build();
try {
final Metadata metadata = new MetadataSources(serviceRegistry).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(serviceRegistry);
}
}
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());
}
Aggregations