本文整理了Java中org.hibernate.boot.Metadata.getCollectionBinding()
方法的一些代码示例,展示了Metadata.getCollectionBinding()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Metadata.getCollectionBinding()
方法的具体详情如下:
包路径:org.hibernate.boot.Metadata
类名称:Metadata
方法名:getCollectionBinding
[英]Retrieves the collection mapping metadata for the given collection role.
[中]检索给定集合角色的集合映射元数据。
代码示例来源:origin: hibernate/hibernate-orm
@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 ) );
}
}
代码示例来源:origin: hibernate/hibernate-orm
@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)
);
}
代码示例来源:origin: hibernate/hibernate-orm
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() );
}
}
代码示例来源:origin: hibernate/hibernate-orm
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() );
}
代码示例来源:origin: hibernate/hibernate-orm
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() );
}
代码示例来源:origin: hibernate/hibernate-orm
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()
);
}
代码示例来源:origin: hibernate/hibernate-orm
@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 );
}
}
}
代码示例来源:origin: hibernate/hibernate-orm
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() ) );
}
代码示例来源:origin: hibernate/hibernate-orm
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());
}
}
代码示例来源:origin: v-ladynev/fluent-hibernate
public static Table getCollectionTable(Metadata metadata, Class<?> persistent,
String propertyName) {
Collection result = metadata
.getCollectionBinding(persistent.getName() + "." + propertyName);
assertThat(result).isNotNull();
return result.getCollectionTable();
}
代码示例来源:origin: v-ladynev/fluent-hibernate
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();
}
代码示例来源:origin: org.hibernate/hibernate-tools
if (metadata.getCollectionBinding(fullRolePath)!=null) {
log.debug(fullRolePath + " found twice!");
代码示例来源:origin: hibernate/hibernate-tools
if (metadata.getCollectionBinding(fullRolePath)!=null) {
log.debug(fullRolePath + " found twice!");
内容来源于网络,如有侵权,请联系作者删除!