org.hibernate.boot.Metadata.getEntityBinding()方法的使用及代码示例

x33g5p2x  于2022-01-25 转载在 其他  
字(11.7k)|赞(0)|评价(0)|浏览(127)

本文整理了Java中org.hibernate.boot.Metadata.getEntityBinding()方法的一些代码示例,展示了Metadata.getEntityBinding()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Metadata.getEntityBinding()方法的具体详情如下:
包路径:org.hibernate.boot.Metadata
类名称:Metadata
方法名:getEntityBinding

Metadata.getEntityBinding介绍

[英]Retrieves the PersistentClass entity mapping metadata representation for the given entity name.
[中]检索给定实体名称的PersistentClass实体映射元数据表示形式。

代码示例

代码示例来源:origin: hibernate/hibernate-orm

@Test
public void testAllSeparateInOne() {
  Metadata metadata = new MetadataSources( serviceRegistry )
      .addResource( getBaseForMappings() + "extendshbm/allseparateinone.hbm.xml" )
      .buildMetadata();
  assertNotNull( metadata.getEntityBinding( "org.hibernate.test.extendshbm.Customer" ) );
  assertNotNull( metadata.getEntityBinding( "org.hibernate.test.extendshbm.Person" ) );
  assertNotNull( metadata.getEntityBinding( "org.hibernate.test.extendshbm.Employee" ) );
}

代码示例来源:origin: hibernate/hibernate-orm

@Test
public void testAllInOne() {
  Metadata metadata = new MetadataSources( serviceRegistry )
      .addResource( getBaseForMappings() + "extendshbm/allinone.hbm.xml" )
      .buildMetadata();
  assertNotNull( metadata.getEntityBinding( "org.hibernate.test.extendshbm.Customer" ) );
  assertNotNull( metadata.getEntityBinding( "org.hibernate.test.extendshbm.Person" ) );
  assertNotNull( metadata.getEntityBinding( "org.hibernate.test.extendshbm.Employee" ) );
}

代码示例来源:origin: hibernate/hibernate-orm

@Test
public void testUnionSubclass() {
  Metadata metadata = new MetadataSources( serviceRegistry )
      .addResource( getBaseForMappings() + "extendshbm/unionsubclass.hbm.xml" )
      .buildMetadata();
  assertNotNull( metadata.getEntityBinding( "org.hibernate.test.extendshbm.Person" ) );
  assertNotNull( metadata.getEntityBinding( "org.hibernate.test.extendshbm.Customer" ) );
}

代码示例来源:origin: hibernate/hibernate-orm

@Test
public void testEntityNamesWithPackage() {
  Metadata metadata = new MetadataSources( serviceRegistry )
      .addResource( getBaseForMappings() + "extendshbm/packageentitynames.hbm.xml" )
      .buildMetadata();
  assertNotNull( metadata.getEntityBinding( "EntityHasName" ) );
  assertNotNull( metadata.getEntityBinding( "EntityCompany" ) );
}

代码示例来源:origin: hibernate/hibernate-orm

@Test
public void testJoinedSubclassAndEntityNamesOnly() {
  Metadata metadata = new MetadataSources( serviceRegistry )
      .addResource( getBaseForMappings() + "extendshbm/entitynames.hbm.xml" )
      .buildMetadata();
  assertNotNull( metadata.getEntityBinding( "EntityHasName" ) );
  assertNotNull( metadata.getEntityBinding( "EntityCompany" ) );
}

代码示例来源:origin: hibernate/hibernate-orm

@Test
public void testOutOfOrder() {
  Metadata metadata = new MetadataSources( serviceRegistry )
      .addResource( getBaseForMappings() + "extendshbm/Customer.hbm.xml" )
      .addResource( getBaseForMappings() + "extendshbm/Person.hbm.xml" )
      .addResource( getBaseForMappings() + "extendshbm/Employee.hbm.xml" )
      .buildMetadata();
  assertNotNull( metadata.getEntityBinding( "org.hibernate.test.extendshbm.Customer" ) );
  assertNotNull( metadata.getEntityBinding( "org.hibernate.test.extendshbm.Person" ) );
  assertNotNull( metadata.getEntityBinding( "org.hibernate.test.extendshbm.Employee" ) );
}

代码示例来源:origin: hibernate/hibernate-orm

@Test
public void testAttributeAccessorConfiguration() {
  final Metadata metadata = new MetadataSources( serviceRegistry )
      .addAnnotatedClass( Foo.class )
      .buildMetadata();
  final Property property = metadata.getEntityBinding( Foo.class.getName() ).getProperty( "name" );
  assertEquals( BasicAttributeAccessor.class.getName(), property.getPropertyAccessorName() );
}

代码示例来源:origin: hibernate/hibernate-orm

@Test
public void testNwaitingForSuper() {
  Metadata metadata = new MetadataSources( serviceRegistry )
      .addResource( getBaseForMappings() + "extendshbm/Customer.hbm.xml" )
      .addResource( getBaseForMappings() + "extendshbm/Employee.hbm.xml" )
      .addResource( getBaseForMappings() + "extendshbm/Person.hbm.xml" )
      .buildMetadata();
  assertNotNull( metadata.getEntityBinding( "org.hibernate.test.extendshbm.Customer" ) );
  assertNotNull( metadata.getEntityBinding( "org.hibernate.test.extendshbm.Person" ) );
  assertNotNull( metadata.getEntityBinding( "org.hibernate.test.extendshbm.Employee" ) );
}

代码示例来源:origin: hibernate/hibernate-orm

@Test
public void testWithCustomNamingStrategy() throws Exception {
  Metadata metadata = new MetadataSources( serviceRegistry )
      .addAnnotatedClass(Address.class)
      .addAnnotatedClass(Person.class)
      .getMetadataBuilder()
      .applyImplicitNamingStrategy( new LongIdentifierNamingStrategy() )
      .build();
  UniqueKey uniqueKey = metadata.getEntityBinding( Address.class.getName()).getTable().getUniqueKeyIterator().next();
  assertEquals( expectedUniqueKeyName(), uniqueKey.getName() );
  org.hibernate.mapping.ForeignKey foreignKey =
      (org.hibernate.mapping.ForeignKey) metadata.getEntityBinding( Address.class.getName()).getTable().getForeignKeyIterator().next();
  assertEquals( expectedForeignKeyName(), foreignKey.getName() );
  org.hibernate.mapping.Index index = metadata.getEntityBinding( Address.class.getName()).getTable().getIndexIterator().next();
  assertEquals( expectedIndexName(), index.getName() );
}

代码示例来源:origin: hibernate/hibernate-orm

@Test
public void testHbmXmlHandling() {
  final Metadata metadata = new MetadataSources( ssr )
      .addResource( "org/hibernate/test/namingstrategy/synchronizedTables/mapping.hbm.xml" )
      .getMetadataBuilder()
      .applyPhysicalNamingStrategy( TestingPhysicalNamingStrategy.INSTANCE )
      .build();
  verify( metadata.getEntityBinding( DynamicEntity.class.getName() ) );
}

代码示例来源:origin: hibernate/hibernate-orm

@Test
public void testAnnotationHandling() {
  final Metadata metadata = new MetadataSources( ssr )
      .addAnnotatedClass( DynamicEntity.class )
      .getMetadataBuilder()
      .applyPhysicalNamingStrategy( TestingPhysicalNamingStrategy.INSTANCE )
      .build();
  verify( metadata.getEntityBinding( DynamicEntity.class.getName() ) );
}

代码示例来源:origin: hibernate/hibernate-orm

@Test
  public void testComparator() {
    PersistentClass cm = metadata.getEntityBinding( "org.hibernate.test.legacy.Wicked" );
    
    Property property = cm.getProperty("sortedEmployee");
    Collection col = (Collection) property.getValue();
    assertEquals(col.getComparatorClassName(),"org.hibernate.test.legacy.NonExistingComparator");
  }
}

代码示例来源:origin: hibernate/hibernate-orm

@Test
public void testNoCircularityDetection() {
  StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().build();
  try {
    final Metadata metadata = new MetadataSources( ssr )
        .addAnnotatedClass( Entity1.class )
        .addAnnotatedClass( Entity2.class )
        .buildMetadata();
    org.hibernate.mapping.Table entity1Table = metadata.getEntityBinding( Entity1.class.getName() ).getTable();
    org.hibernate.mapping.Table entity2Table = metadata.getEntityBinding( Entity2.class.getName() ).getTable();
    assertTrue( entity1Table.getName().equals( entity2Table.getName() ) );
    assertFalse( entity1Table.getSchema().equals( entity2Table.getSchema() ) );
  }
  finally {
    StandardServiceRegistryBuilder.destroy( ssr );
  }
}

代码示例来源:origin: hibernate/hibernate-orm

@Test
public void testMappingAttributeWithLobAndAttributeConverter() {
  final Metadata metadata = new MetadataSources( ssr )
      .addAnnotatedClass( EntityImpl.class )
      .buildMetadata();
  final Type type = metadata.getEntityBinding( EntityImpl.class.getName() ).getProperty( "status" ).getType();
  final AttributeConverterTypeAdapter concreteType = assertTyping( AttributeConverterTypeAdapter.class, type );
  assertEquals( Types.BLOB, concreteType.getSqlTypeDescriptor().getSqlType() );
}

代码示例来源:origin: hibernate/hibernate-orm

@Test
public void testClassComment() {
  StandardServiceRegistryBuilder serviceRegistryBuilder = new StandardServiceRegistryBuilder()
      .applySetting("hibernate.dialect", "org.hibernate.dialect.HSQLDialect");
  MetadataSources metadataSources = new MetadataSources(serviceRegistryBuilder.build());
  metadataSources.addInputStream(new ReaderInputStream(new StringReader(CLASS_COMMENT_HBM_XML)));
  Metadata metadata = metadataSources.buildMetadata();
  PersistentClass pc = metadata.getEntityBinding("org.hibernate.test.hbm.Foo");
  Assert.assertNotNull(pc);
  Table table = pc.getTable();
  Assert.assertNotNull(table);
  Assert.assertEquals("This is class 'Foo' with property 'bar'.", table.getComment());
}

代码示例来源:origin: hibernate/hibernate-orm

@Test
public void testCollectionAsBasic() {
  StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().build();
  try {
    Metadata metadata = new MetadataSources(ssr).addAnnotatedClass( Post.class )
        .getMetadataBuilder().applyBasicType( new DelimitedStringsType() )
        .build();
    PersistentClass postBinding = metadata.getEntityBinding( Post.class.getName() );
    Property tagsAttribute = postBinding.getProperty( "tags" );
  }
  finally {
    StandardServiceRegistryBuilder.destroy( ssr );
  }
}

代码示例来源:origin: hibernate/hibernate-orm

@Test
public void testExplicitIncrementGenerator() {
  final StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().build();
  final Metadata bootModel = new MetadataSources( ssr )
      .addAnnotatedClass( ExplicitIncrementGeneratorEntity.class )
      .buildMetadata();
  final PersistentClass entityMapping = bootModel.getEntityBinding( ExplicitIncrementGeneratorEntity.class.getName() );
  final IdentifierGenerator generator  = entityMapping.getIdentifier().createIdentifierGenerator(
      bootModel.getIdentifierGeneratorFactory(),
      ssr.getService( JdbcEnvironment.class ).getDialect(),
      null,
      null,
      (RootClass) entityMapping
  );
  assertTyping( IncrementGenerator.class, generator );
}

代码示例来源:origin: hibernate/hibernate-orm

@Test
public void testImplicitIncrementGenerator() {
  final StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().build();
  final Metadata bootModel = new MetadataSources( ssr )
      .addAnnotatedClass( ImplicitIncrementGeneratorEntity.class )
      .buildMetadata();
  final PersistentClass entityMapping = bootModel.getEntityBinding( ImplicitIncrementGeneratorEntity.class.getName() );
  final IdentifierGenerator generator  = entityMapping.getIdentifier().createIdentifierGenerator(
      bootModel.getIdentifierGeneratorFactory(),
      ssr.getService( JdbcEnvironment.class ).getDialect(),
      null,
      null,
      (RootClass) entityMapping
  );
  assertTyping( IncrementGenerator.class, generator );
}

代码示例来源:origin: hibernate/hibernate-orm

@Test
  public void testOrmXmlDefinedEnumType() {
    StandardServiceRegistry ssr = ServiceRegistryBuilder.buildServiceRegistry();

    try {
      MetadataSources ms = new MetadataSources( ssr );
      ms.addResource( "org/hibernate/test/annotations/enumerated/ormXml/orm.xml" );

      Metadata metadata = ms.buildMetadata();

      Type bindingPropertyType = metadata.getEntityBinding( BookWithOrmEnum.class.getName() )
          .getProperty( "bindingStringEnum" )
          .getType();
      CustomType customType = ExtraAssertions.assertTyping( CustomType.class, bindingPropertyType );
      EnumType enumType = ExtraAssertions.assertTyping( EnumType.class, customType.getUserType() );
      assertFalse( enumType.isOrdinal() );
    }
    finally {
      ServiceRegistryBuilder.destroy( ssr );
    }
  }
}

代码示例来源:origin: hibernate/hibernate-orm

protected void validateCustomer(Metadata metadata) {
  final PersistentClass customerBinding = metadata.getEntityBinding( Customer.class.getName() );
  assertNotNull( customerBinding );
  validateCustomerPrimaryTableName( customerBinding.getTable().getQuotedName() );
  assertEquals( 1, customerBinding.getIdentifier().getColumnSpan() );
  validateCustomerPrimaryKeyColumn( (Column) customerBinding.getIdentifier().getColumnIterator().next() );
  assertNotNull( customerBinding.getVersion() );
  assertEquals( 1, customerBinding.getVersion().getColumnSpan() );
  validateCustomerVersionColumn( (Column) customerBinding.getVersion().getColumnIterator().next() );
  final Property nameBinding = customerBinding.getProperty( "name" );
  assertNotNull( nameBinding );
  assertEquals( 1, nameBinding.getColumnSpan() );
  validateCustomerNameColumn( (Column) nameBinding.getColumnIterator().next() );
  final Property hqAddressBinding = customerBinding.getProperty( "hqAddress" );
  assertNotNull( hqAddressBinding );
  assertEquals( 3, hqAddressBinding.getColumnSpan() );
  validateCustomerHqAddressComponent( assertTyping( Component.class, hqAddressBinding.getValue() ) );
}

相关文章