@Override protected void afterMetadataBuilt(Metadata metadata) { Collection children = metadata.getCollectionBinding( Parent.class.getName() + ".children" ); Component childComponents = ( Component ) children.getElement(); Formula f = ( Formula ) childComponents.getProperty( "bioLength" ).getValue().getColumnIterator().next(); SQLFunction lengthFunction = metadata.getDatabase().getJdbcEnvironment().getDialect().getFunctions().get( "length" ); if ( lengthFunction != null ) { ArrayList args = new ArrayList(); args.add( "bio" ); f.setFormula( lengthFunction.render( StandardBasicTypes.INTEGER, args, null ) ); } }
@Test public void testWithJpaCompliantNamingStrategy() throws Exception { Metadata metadata = new MetadataSources( serviceRegistry ) .addAnnotatedClass( A.class ) .addAnnotatedClass( AddressEntry.class ) .getMetadataBuilder() .applyImplicitNamingStrategy( ImplicitNamingStrategyJpaCompliantImpl.INSTANCE ) .build(); Collection collectionBinding = metadata.getCollectionBinding( A.class.getName() + ".address" ); assertEquals( "Expecting A#address collection table name (implicit) to be [A_address] per JPA spec (section 11.1.8)", "A_ADDRESS", collectionBinding.getCollectionTable().getQuotedName().toUpperCase(Locale.ROOT) ); }
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() ); } }
protected void validateCustomerIndustries(Metadata metadata) { final Collection collectionBinding = metadata.getCollectionBinding( Customer.class.getName() + ".industries" ); assertNotNull( collectionBinding ); validateCustomerIndustriesTableName( collectionBinding.getCollectionTable().getQuotedName() ); assertEquals( 1, collectionBinding.getKey().getColumnSpan() ); validateCustomerIndustriesKeyColumn( (Column) collectionBinding.getKey().getColumnIterator().next() ); assertEquals( 1, collectionBinding.getElement().getColumnSpan() ); validateCustomerIndustriesElementColumn( (Column) collectionBinding.getElement().getColumnIterator().next() ); }
protected void validateCustomerOrders(Metadata metadata) { final Collection collectionBinding = metadata.getCollectionBinding( Customer.class.getName() + ".orders" ); assertNotNull( collectionBinding ); validateCustomerOrdersTableName( collectionBinding.getCollectionTable().getQuotedName() ); assertEquals( 1, collectionBinding.getKey().getColumnSpan() ); validateCustomerOrdersKeyColumn( (Column) collectionBinding.getKey().getColumnIterator().next() ); assertEquals( 1, collectionBinding.getElement().getColumnSpan() ); validateCustomerOrdersElementColumn( (Column) collectionBinding.getElement().getColumnIterator().next() ); }
protected void validateCustomerRegisteredTrademarks(Metadata metadata) { final Collection collectionBinding = metadata.getCollectionBinding( Customer.class.getName() + ".registeredTrademarks" ); assertNotNull( collectionBinding ); validateCustomerRegisteredTrademarksTableName( collectionBinding.getCollectionTable().getQuotedName() ); assertEquals( 1, collectionBinding.getKey().getColumnSpan() ); validateCustomerRegisteredTrademarksKeyColumn( (Column) collectionBinding.getKey().getColumnIterator().next() ); assertEquals( 1, collectionBinding.getElement().getColumnSpan() ); validateCustomerRegisteredTrademarksElementColumn( (Column) collectionBinding.getElement() .getColumnIterator() .next() ); }
@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 ); } } }
protected void validateCustomerAddresses(Metadata metadata) { final Collection collectionBinding = metadata.getCollectionBinding( Customer.class.getName() + ".addresses" ); assertNotNull( collectionBinding ); validateCustomerAddressesTableName( collectionBinding.getCollectionTable().getQuotedName() ); assertEquals( 1, collectionBinding.getKey().getColumnSpan() ); validateCustomerAddressesKeyColumn( (Column) collectionBinding.getKey().getColumnIterator().next() ); assertEquals( 3, collectionBinding.getElement().getColumnSpan() ); validateCustomerAddressesElementComponent( assertTyping( Component.class, collectionBinding.getElement() ) ); }
protected void checkDefaultJoinTableAndAllColumnNames( Metadata metadata, Class<?> ownerEntityClass, String ownerCollectionPropertyName, String expectedCollectionTableName, String ownerForeignKeyNameExpected, String[] columnNames) { final org.hibernate.mapping.Collection collection = metadata.getCollectionBinding( ownerEntityClass.getName() + '.' + ownerCollectionPropertyName ); final org.hibernate.mapping.Table table = collection.getCollectionTable(); assertEquals( expectedCollectionTableName, table.getName() ); // The default owner and inverse join columns can only be computed if they have PK with 1 column. assertEquals( 1, collection.getOwner().getKey().getColumnSpan() ); assertEquals( ownerForeignKeyNameExpected, collection.getKey().getColumnIterator().next().getText() ); int columnNumber = table.getColumnSpan(); for ( int i = 0; i < columnNumber; i++ ) { assertEquals( columnNames[i], table.getColumn( i + 1 ).getName()); } }
public static Table getCollectionTable(Metadata metadata, Class<?> persistent, String propertyName) { Collection result = metadata .getCollectionBinding(persistent.getName() + "." + propertyName); assertThat(result).isNotNull(); return result.getCollectionTable(); }
private static Table getUserPhonesTable(StrategyOptions options) { Metadata metadata = StrategyTestUtils.createMetadata(serviceRegistry, new Hibernate5NamingStrategy(options), ENTITIES); Collection binding = metadata.getCollectionBinding(User.class.getName() + ".phones"); assertThat(binding).isNotNull(); return binding.getCollectionTable(); }
if (metadata.getCollectionBinding(fullRolePath)!=null) { log.debug(fullRolePath + " found twice!");
if (metadata.getCollectionBinding(fullRolePath)!=null) { log.debug(fullRolePath + " found twice!");