private SessionFactory buildSessionFactory() {
    // Extra options located in src/test/resources/hibernate.properties
    Properties envProps = Environment.getProperties();
    envProps.setProperty(Environment.DIALECT, "HSQL");
    envProps.setProperty(Environment.HBM2DDL_AUTO, "create-drop");
    envProps.setProperty(
        Environment.CONNECTION_PROVIDER, JtaAwareConnectionProviderImpl.class.getName());
    envProps.setProperty(Environment.JNDI_CLASS, "org.jnp.interfaces.NamingContextFactory");
    envProps.setProperty(Environment.TRANSACTION_STRATEGY, "jta");
    envProps.setProperty(Environment.CURRENT_SESSION_CONTEXT_CLASS, "jta");
    envProps.setProperty(Environment.RELEASE_CONNECTIONS, "auto");
    envProps.setProperty(Environment.USE_SECOND_LEVEL_CACHE, "true");
    envProps.setProperty(Environment.USE_QUERY_CACHE, "true");
    envProps.put(AvailableSettings.JTA_PLATFORM, new JBossStandAloneJtaPlatform());
    envProps.setProperty(
        Environment.CACHE_REGION_FACTORY,
        "org.hibernate.test.cache.infinispan.functional.SingleNodeTestCase$TestInfinispanRegionFactory");
    serviceRegistry = ServiceRegistryBuilder.buildServiceRegistry(envProps);

    MetadataSources sources = new MetadataSources(serviceRegistry);

    String[] mappings =
        new String[] {"org/hibernate/test/cache/infinispan/functional/Item.hbm.xml"};
    for (String mapping : mappings) {
      sources.addResource(mapping);
    }
    Metadata metadata = sources.buildMetadata();
    Iterator<EntityBinding> entityIter = metadata.getEntityBindings().iterator();
    while (entityIter.hasNext()) {
      EntityBinding binding = entityIter.next();
      binding.getHierarchyDetails().getCaching().setAccessType(AccessType.TRANSACTIONAL);
      binding.getHierarchyDetails().getCaching().setRequested(TruthValue.TRUE);
      binding.getHierarchyDetails().getCaching().setRegion(binding.getEntityName());
      binding.getHierarchyDetails().getCaching().setCacheLazyProperties(true);
    }
    Iterator<PluralAttributeBinding> collectionIter = metadata.getCollectionBindings().iterator();
    while (collectionIter.hasNext()) {
      PluralAttributeBinding binding = collectionIter.next();
      binding.getCaching().setAccessType(AccessType.TRANSACTIONAL);
      binding.getCaching().setRequested(TruthValue.TRUE);
      binding
          .getCaching()
          .setRegion(
              StringHelper.qualify(
                  binding.getContainer().seekEntityBinding().getEntityName(),
                  binding.getAttribute().getName()));
      binding.getCaching().setCacheLazyProperties(true);
    }
    return metadata.buildSessionFactory();
  }
 @Test
 @Resources(annotatedClasses = VersionBindingTests.Item2.class)
 public void testVersionUnsavedValue() {
   EntityBinding binding = getEntityBinding(Item2.class);
   assertTrue(binding.isVersioned());
   assertEquals("undefined", binding.getHierarchyDetails().getEntityVersion().getUnsavedValue());
 }
Example #3
0
 @Test
 @Resources(annotatedClasses = {User.class, Address.class})
 public void testEmbeddable() {
   EntityBinding binding = getEntityBinding(User.class);
   EntityIdentifier identifier = binding.getHierarchyDetails().getEntityIdentifier();
   assertTrue(!identifier.isNonAggregatedComposite());
   assertEquals(identifier.getNature(), EntityIdentifierNature.AGGREGATED_COMPOSITE);
 }
  /**
   * Used to instantiate the EntityBinding for an entity that is a subclass (sub-entity) in an
   * inheritance hierarchy
   *
   * @param superEntityBinding The entity binding of this binding's super
   */
  public EntityBinding(EntityBinding superEntityBinding) {
    this.superEntityBinding = superEntityBinding;
    this.hierarchyDetails = superEntityBinding.getHierarchyDetails();
    this.subEntityBindingId = superEntityBinding.nextSubEntityBindingId();

    // TODO: the ID attribute binding needs to be recreated for this EntityBinding
    // otherwise, this !=
    // hierarchyDetails.getEntityIdentifier().getAttributeBinding().getContainer()
  }
 @Test
 @Resources(annotatedClasses = VersionBindingTests.Item2.class)
 public void testVersionTypeAttribute() {
   EntityBinding binding = getEntityBinding(Item2.class);
   assertTrue(binding.isVersioned());
   HibernateTypeDescriptor descriptor =
       binding
           .getHierarchyDetails()
           .getEntityVersion()
           .getVersioningAttributeBinding()
           .getHibernateTypeDescriptor();
   //		assertEquals( "Long", descriptor.getExplicitTypeName() );
   assertEquals(Long.class.getName(), descriptor.getClassReference().getName());
   assertEquals(Long.class, descriptor.getClassReference().getResolvedClass());
   assertNotNull(descriptor.getResolvedTypeMapping());
   assertEquals(LongType.class, descriptor.getResolvedTypeMapping().getClass());
   assertNotNull(descriptor.getTypeParameters());
   assertTrue(descriptor.getTypeParameters().isEmpty());
 }
 @Test
 @Resources(annotatedClasses = {TableWithUniqueConstraint.class, SecondTable.class})
 public void testTableUniqueConstraints() {
   EntityBinding binding = getEntityBinding(TableWithUniqueConstraint.class);
   testTableUniqueConstraints(binding.getPrimaryTable(), "u1", 2);
   testTableUniqueConstraints(
       ((MultipleHiLoPerTableGenerator)
               binding.getHierarchyDetails().getEntityIdentifier().getIdentifierGenerator())
           .getTable(),
       "u2",
       1);
   testTableUniqueConstraints(
       SchemaUtil.getCollection(TableWithUniqueConstraint.class, "secondTables", meta)
           .getPluralAttributeKeyBinding()
           .getCollectionTable(),
       "u3",
       2);
   testTableUniqueConstraints(
       SchemaUtil.getCollection(TableWithUniqueConstraint.class, "elements", meta)
           .getPluralAttributeKeyBinding()
           .getCollectionTable(),
       "u4",
       1);
 }