Search in sources :

Example 6 with PersistentClass

use of org.hibernate.mapping.PersistentClass in project hibernate-orm by hibernate.

the class SecondLevelCacheStressTestCase method buildMetadata.

private static Metadata buildMetadata(StandardServiceRegistry registry) {
    final String cacheStrategy = "transactional";
    MetadataSources metadataSources = new MetadataSources(registry);
    for (Class entityClass : getAnnotatedClasses()) {
        metadataSources.addAnnotatedClass(entityClass);
    }
    Metadata metadata = metadataSources.buildMetadata();
    for (PersistentClass entityBinding : metadata.getEntityBindings()) {
        if (!entityBinding.isInherited()) {
            ((RootClass) entityBinding).setCacheConcurrencyStrategy(cacheStrategy);
        }
    }
    for (Collection collectionBinding : metadata.getCollectionBindings()) {
        collectionBinding.setCacheConcurrencyStrategy(cacheStrategy);
    }
    return metadata;
}
Also used : RootClass(org.hibernate.mapping.RootClass) MetadataSources(org.hibernate.boot.MetadataSources) Metadata(org.hibernate.boot.Metadata) Collection(org.hibernate.mapping.Collection) RootClass(org.hibernate.mapping.RootClass) PersistentClass(org.hibernate.mapping.PersistentClass) PersistentClass(org.hibernate.mapping.PersistentClass)

Example 7 with PersistentClass

use of org.hibernate.mapping.PersistentClass in project hibernate-orm by hibernate.

the class JBossStandaloneJtaExampleTest method buildSessionFactory.

private SessionFactory buildSessionFactory() {
    // Extra options located in src/test/resources/hibernate.properties
    StandardServiceRegistryBuilder ssrb = new StandardServiceRegistryBuilder().applySetting(Environment.DIALECT, "HSQL").applySetting(Environment.HBM2DDL_AUTO, "create-drop").applySetting(Environment.CONNECTION_PROVIDER, JtaAwareConnectionProviderImpl.class.getName()).applySetting(Environment.JNDI_CLASS, "org.jnp.interfaces.NamingContextFactory").applySetting(Environment.TRANSACTION_COORDINATOR_STRATEGY, JtaTransactionCoordinatorBuilderImpl.class.getName()).applySetting(Environment.CURRENT_SESSION_CONTEXT_CLASS, "jta").applySetting(Environment.RELEASE_CONNECTIONS, "auto").applySetting(Environment.USE_SECOND_LEVEL_CACHE, "true").applySetting(Environment.USE_QUERY_CACHE, "true").applySetting(Environment.JTA_PLATFORM, new JBossStandAloneJtaPlatform()).applySetting(Environment.CACHE_REGION_FACTORY, TestInfinispanRegionFactory.class.getName());
    StandardServiceRegistry serviceRegistry = ssrb.build();
    MetadataSources metadataSources = new MetadataSources(serviceRegistry);
    metadataSources.addResource("org/hibernate/test/cache/infinispan/functional/entities/Item.hbm.xml");
    Metadata metadata = metadataSources.buildMetadata();
    for (PersistentClass entityBinding : metadata.getEntityBindings()) {
        if (entityBinding instanceof RootClass) {
            ((RootClass) entityBinding).setCacheConcurrencyStrategy("transactional");
        }
    }
    for (Collection collectionBinding : metadata.getCollectionBindings()) {
        collectionBinding.setCacheConcurrencyStrategy("transactional");
    }
    return metadata.buildSessionFactory();
}
Also used : RootClass(org.hibernate.mapping.RootClass) JtaAwareConnectionProviderImpl(org.hibernate.testing.jta.JtaAwareConnectionProviderImpl) JtaTransactionCoordinatorBuilderImpl(org.hibernate.resource.transaction.backend.jta.internal.JtaTransactionCoordinatorBuilderImpl) StandardServiceRegistryBuilder(org.hibernate.boot.registry.StandardServiceRegistryBuilder) MetadataSources(org.hibernate.boot.MetadataSources) Metadata(org.hibernate.boot.Metadata) Collection(org.hibernate.mapping.Collection) JBossStandAloneJtaPlatform(org.hibernate.engine.transaction.jta.platform.internal.JBossStandAloneJtaPlatform) TestInfinispanRegionFactory(org.hibernate.test.cache.infinispan.util.TestInfinispanRegionFactory) StandardServiceRegistry(org.hibernate.boot.registry.StandardServiceRegistry) PersistentClass(org.hibernate.mapping.PersistentClass)

Example 8 with PersistentClass

use of org.hibernate.mapping.PersistentClass in project hibernate-orm by hibernate.

the class CollectionMetadataGenerator method getMappedBy.

private String getMappedBy(Collection collectionValue) {
    final PersistentClass referencedClass = getReferenceCollectionClass(collectionValue);
    final ValueHolder valueHolder = new ValueHolder(collectionValue);
    return getMappedBy(referencedClass, valueHolder);
}
Also used : PersistentClass(org.hibernate.mapping.PersistentClass)

Example 9 with PersistentClass

use of org.hibernate.mapping.PersistentClass in project hibernate-orm by hibernate.

the class VersionsJoinTableRangeComponentNamingTest method testJoinColumnNamesComponent2.

@Test
public void testJoinColumnNamesComponent2() {
    PersistentClass auditClass = metadata().getEntityBinding(COMPONENT_2_AUDIT_JOIN_TABLE_NAME);
    assert auditClass != null;
    @SuppressWarnings({ "unchecked" }) Iterator<Column> columns = auditClass.getTable().getColumnIterator();
    boolean id1Found = false;
    boolean id2Found = false;
    while (columns.hasNext()) {
        Column column = columns.next();
        if ("VJTRCTE2_ID".equals(column.getName())) {
            id1Found = true;
        }
        if ("VJTRTAE_ID".equals(column.getName())) {
            id2Found = true;
        }
    }
    assert id1Found && id2Found;
}
Also used : Column(org.hibernate.mapping.Column) PersistentClass(org.hibernate.mapping.PersistentClass) Test(org.junit.Test)

Example 10 with PersistentClass

use of org.hibernate.mapping.PersistentClass in project hibernate-orm by hibernate.

the class VersionsJoinTableRangeComponentNamingTest method testOverrideNotAudited.

/**
	 * Verify that
	 * {@link VersionsJoinTableRangeComponentTestEntity#getComponent3()} is
	 * partially audited.
	 */
@Test
public void testOverrideNotAudited() {
    PersistentClass auditClass = metadata().getEntityBinding(VersionsJoinTableRangeComponentTestEntity.class.getName() + "_AUD");
    assert auditClass != null;
    @SuppressWarnings({ "unchecked" }) Iterator<Column> columns = auditClass.getTable().getColumnIterator();
    boolean auditColumn1Found = false;
    boolean auditColumn2Found = false;
    while (columns.hasNext()) {
        Column column = columns.next();
        if ("STR1".equals(column.getName())) {
            auditColumn1Found = true;
        }
        if ("STR2".equals(column.getName())) {
            auditColumn2Found = true;
        }
    }
    assert auditColumn1Found && !auditColumn2Found;
}
Also used : Column(org.hibernate.mapping.Column) PersistentClass(org.hibernate.mapping.PersistentClass) Test(org.junit.Test)

Aggregations

PersistentClass (org.hibernate.mapping.PersistentClass)140 Test (org.junit.Test)70 Property (org.hibernate.mapping.Property)52 MetadataSources (org.hibernate.boot.MetadataSources)36 Column (org.hibernate.mapping.Column)36 Metadata (org.hibernate.boot.Metadata)28 StandardServiceRegistryBuilder (org.hibernate.boot.registry.StandardServiceRegistryBuilder)26 Iterator (java.util.Iterator)25 StandardServiceRegistry (org.hibernate.boot.registry.StandardServiceRegistry)24 SimpleValue (org.hibernate.mapping.SimpleValue)19 MappingException (org.hibernate.MappingException)18 Collection (org.hibernate.mapping.Collection)18 TestForIssue (org.hibernate.testing.TestForIssue)18 Component (org.hibernate.mapping.Component)17 MetadataImplementor (org.hibernate.boot.spi.MetadataImplementor)15 AnnotationException (org.hibernate.AnnotationException)14 RootClass (org.hibernate.mapping.RootClass)14 Table (org.hibernate.mapping.Table)14 HashMap (java.util.HashMap)13 Type (org.hibernate.type.Type)13