use of org.hibernate.mapping.SimpleValue 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.SimpleValue 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.SimpleValue in project hibernate-orm by hibernate.
the class ComponentNamingStrategyTest method testComponentSafeNamingStrategy.
@Test
@TestForIssue(jiraKey = "HHH-6005")
public void testComponentSafeNamingStrategy() {
final StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().build();
try {
final MetadataSources ms = new MetadataSources(ssr);
ms.addAnnotatedClass(Container.class).addAnnotatedClass(Item.class);
final Metadata metadata = ms.getMetadataBuilder().applyImplicitNamingStrategy(ImplicitNamingStrategyComponentPathImpl.INSTANCE).build();
final PersistentClass pc = metadata.getEntityBinding(Container.class.getName());
Property p = pc.getProperty("items");
Bag value = assertTyping(Bag.class, p.getValue());
SimpleValue elementValue = assertTyping(SimpleValue.class, value.getElement());
assertEquals(1, elementValue.getColumnSpan());
Column column = assertTyping(Column.class, elementValue.getColumnIterator().next());
assertEquals("items_name", column.getName());
} finally {
StandardServiceRegistryBuilder.destroy(ssr);
}
}
use of org.hibernate.mapping.SimpleValue in project hibernate-orm by hibernate.
the class ComponentNamingStrategyTest method testDefaultNamingStrategy.
@Test
public void testDefaultNamingStrategy() {
final StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().build();
try {
final MetadataSources ms = new MetadataSources(ssr);
ms.addAnnotatedClass(Container.class).addAnnotatedClass(Item.class);
final Metadata metadata = ms.getMetadataBuilder().applyImplicitNamingStrategy(ImplicitNamingStrategyJpaCompliantImpl.INSTANCE).build();
final PersistentClass pc = metadata.getEntityBinding(Container.class.getName());
Property p = pc.getProperty("items");
Bag value = assertTyping(Bag.class, p.getValue());
SimpleValue elementValue = assertTyping(SimpleValue.class, value.getElement());
assertEquals(1, elementValue.getColumnSpan());
Column column = assertTyping(Column.class, elementValue.getColumnIterator().next());
assertEquals(column.getName(), "name");
} finally {
StandardServiceRegistryBuilder.destroy(ssr);
}
}
use of org.hibernate.mapping.SimpleValue in project hibernate-orm by hibernate.
the class EntityBinder method setFKNameIfDefined.
private void setFKNameIfDefined(Join join) {
// just awful..
org.hibernate.annotations.Table matchingTable = findMatchingComplimentTableAnnotation(join);
if (matchingTable != null && !BinderHelper.isEmptyAnnotationValue(matchingTable.foreignKey().name())) {
((SimpleValue) join.getKey()).setForeignKeyName(matchingTable.foreignKey().name());
} else {
javax.persistence.SecondaryTable jpaSecondaryTable = findMatchingSecondaryTable(join);
if (jpaSecondaryTable != null) {
if (jpaSecondaryTable.foreignKey().value() == ConstraintMode.NO_CONSTRAINT) {
((SimpleValue) join.getKey()).setForeignKeyName("none");
} else {
((SimpleValue) join.getKey()).setForeignKeyName(StringHelper.nullIfEmpty(jpaSecondaryTable.foreignKey().name()));
((SimpleValue) join.getKey()).setForeignKeyDefinition(StringHelper.nullIfEmpty(jpaSecondaryTable.foreignKey().foreignKeyDefinition()));
}
}
}
}
Aggregations