Java Code Examples for org.hibernate.cfg.Configuration#addPackage()

The following examples show how to use org.hibernate.cfg.Configuration#addPackage() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AbstractTest.java    From hibernate-master-class with Apache License 2.0 6 votes vote down vote up
private SessionFactory newSessionFactory() {
    Properties properties = getProperties();
    Configuration configuration = new Configuration().addProperties(properties);
    for(Class<?> entityClass : entities()) {
        configuration.addAnnotatedClass(entityClass);
    }
    String[] packages = packages();
    if(packages != null) {
        for(String scannedPackage : packages) {
            configuration.addPackage(scannedPackage);
        }
    }
    Interceptor interceptor = interceptor();
    if(interceptor != null) {
        configuration.setInterceptor(interceptor);
    }
    return configuration.buildSessionFactory(
            new StandardServiceRegistryBuilder()
                    .applySettings(properties)
                    .build()
    );
}
 
Example 2
Source File: EagerTest.java    From hibernate-reactive with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
protected Configuration constructConfiguration() {
	Configuration configuration = super.constructConfiguration();
	configuration.addPackage(this.getClass().getPackage().getName());
	configuration.addAnnotatedClass(Node.class);
	configuration.addAnnotatedClass(Element.class);
	return configuration;
}
 
Example 3
Source File: FetchModeSubselectEagerTest.java    From hibernate-reactive with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
protected Configuration constructConfiguration() {
	Configuration configuration = super.constructConfiguration();
	configuration.addPackage(this.getClass().getPackage().getName());
	configuration.addAnnotatedClass(Node.class);
	configuration.addAnnotatedClass(Element.class);
	return configuration;
}
 
Example 4
Source File: FilterTest.java    From hibernate-reactive with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
protected Configuration constructConfiguration() {
	Configuration configuration = super.constructConfiguration();
	configuration.addPackage(this.getClass().getPackage().getName());
	configuration.addAnnotatedClass(Node.class);
	configuration.addAnnotatedClass(Element.class);
	return configuration;
}
 
Example 5
Source File: BaseCoreFunctionalTestCase.java    From google-cloud-spanner-hibernate with GNU Lesser General Public License v2.1 5 votes vote down vote up
protected void addMappings(Configuration configuration) {
  String[] mappings = getMappings();
  if ( mappings != null ) {
    for ( String mapping : mappings ) {
      configuration.addResource(
          getBaseForMappings() + mapping,
          getClass().getClassLoader()
      );
    }
  }
  Class<?>[] annotatedClasses = getAnnotatedClasses();
  if ( annotatedClasses != null ) {
    for ( Class<?> annotatedClass : annotatedClasses ) {
      configuration.addAnnotatedClass( annotatedClass );
    }
  }
  String[] annotatedPackages = getAnnotatedPackages();
  if ( annotatedPackages != null ) {
    for ( String annotatedPackage : annotatedPackages ) {
      configuration.addPackage( annotatedPackage );
    }
  }
  String[] xmlFiles = getXmlFiles();
  if ( xmlFiles != null ) {
    for ( String xmlFile : xmlFiles ) {
      try ( InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream( xmlFile ) ) {
        configuration.addInputStream( is );
      }
      catch (IOException e) {
        throw new IllegalArgumentException( e );
      }
    }
  }
}
 
Example 6
Source File: AnnotationSessionFactoryBean.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Reads metadata from annotated classes and packages into the
 * AnnotationConfiguration instance.
 */
@Override
protected void postProcessMappings(Configuration config) throws HibernateException {
	if (this.annotatedClasses != null) {
		for (Class<?> annotatedClass : this.annotatedClasses) {
			config.addAnnotatedClass(annotatedClass);
		}
	}
	if (this.annotatedPackages != null) {
		for (String annotatedPackage : this.annotatedPackages) {
			config.addPackage(annotatedPackage);
		}
	}
	scanPackages(config);
}
 
Example 7
Source File: AbstractTest.java    From hibernate-types with Apache License 2.0 5 votes vote down vote up
private SessionFactory newSessionFactory() {
    Properties properties = properties();
    Configuration configuration = new Configuration().addProperties(properties);
    for (Class<?> entityClass : entities()) {
        configuration.addAnnotatedClass(entityClass);
    }
    String[] packages = packages();
    if (packages != null) {
        for (String scannedPackage : packages) {
            configuration.addPackage(scannedPackage);
        }
    }
    String[] resources = resources();
    if (resources != null) {
        for (String resource : resources) {
            configuration.addResource(resource);
        }
    }
    Interceptor interceptor = interceptor();
    if (interceptor != null) {
        configuration.setInterceptor(interceptor);
    }
    configuration.setProperties(properties);
    return configuration.buildSessionFactory(
            new BootstrapServiceRegistryBuilder()
                    .build()
    );
}
 
Example 8
Source File: AnnotationSessionFactoryBean.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
/**
 * Reads metadata from annotated classes and packages into the
 * AnnotationConfiguration instance.
 */
@Override
protected void postProcessMappings(Configuration config) throws HibernateException {
	if (this.annotatedClasses != null) {
		for (Class<?> annotatedClass : this.annotatedClasses) {
			config.addAnnotatedClass(annotatedClass);
		}
	}
	if (this.annotatedPackages != null) {
		for (String annotatedPackage : this.annotatedPackages) {
			config.addPackage(annotatedPackage);
		}
	}
	scanPackages(config);
}
 
Example 9
Source File: AbstractTest.java    From hibernate-types with Apache License 2.0 4 votes vote down vote up
private SessionFactory newLegacySessionFactory() {
    Properties properties = properties();
    Configuration configuration = new Configuration().addProperties(properties);
    for (Class<?> entityClass : entities()) {
        configuration.addAnnotatedClass(entityClass);
    }
    String[] packages = packages();
    if (packages != null) {
        for (String scannedPackage : packages) {
            configuration.addPackage(scannedPackage);
        }
    }
    String[] resources = resources();
    if (resources != null) {
        for (String resource : resources) {
            configuration.addResource(resource);
        }
    }
    Interceptor interceptor = interceptor();
    if (interceptor != null) {
        configuration.setInterceptor(interceptor);
    }

    final List<Type> additionalTypes = additionalTypes();
    if (additionalTypes != null) {
        configuration.registerTypeContributor((typeContributions, serviceRegistry) -> {
            additionalTypes.stream().forEach(type -> {
                if (type instanceof BasicType) {
                    typeContributions.contributeType((BasicType) type);
                } else if (type instanceof UserType) {
                    typeContributions.contributeType((UserType) type);
                } else if (type instanceof CompositeUserType) {
                    typeContributions.contributeType((CompositeUserType) type);
                }
            });
        });
    }
    return configuration.buildSessionFactory(
            new StandardServiceRegistryBuilder()
                    .applySettings(properties)
                    .build()
    );
}
 
Example 10
Source File: AbstractTest.java    From hibernate-types with Apache License 2.0 4 votes vote down vote up
private SessionFactory newSessionFactory() {
    Properties properties = properties();
    Configuration configuration = new Configuration().addProperties(properties);
    for (Class<?> entityClass : entities()) {
        configuration.addAnnotatedClass(entityClass);
    }
    String[] packages = packages();
    if (packages != null) {
        for (String scannedPackage : packages) {
            configuration.addPackage(scannedPackage);
        }
    }
    String[] resources = resources();
    if (resources != null) {
        for (String resource : resources) {
            configuration.addResource(resource);
        }
    }
    Interceptor interceptor = interceptor();
    if (interceptor != null) {
        configuration.setInterceptor(interceptor);
    }

    final List<Type> additionalTypes = additionalTypes();
    if (additionalTypes != null) {
        configuration.registerTypeContributor(new TypeContributor() {
            @Override
            public void contribute(TypeContributions typeContributions, ServiceRegistry serviceRegistry) {
                for (Type type : additionalTypes) {
                    if (type instanceof BasicType) {
                        typeContributions.contributeType((BasicType) type);
                    } else if (type instanceof UserType) {
                        typeContributions.contributeType((UserType) type, new String[]{type.getName()});
                    } else if (type instanceof CompositeUserType) {
                        typeContributions.contributeType((CompositeUserType) type, new String[]{type.getName()});
                    }
                }
            }
        });
    }
    return configuration.buildSessionFactory(
            new StandardServiceRegistryBuilder()
                    .applySettings(properties)
                    .build()
    );
}
 
Example 11
Source File: AbstractTest.java    From hibernate-types with Apache License 2.0 4 votes vote down vote up
private SessionFactory newLegacySessionFactory() {
    Properties properties = properties();
    Configuration configuration = new Configuration().addProperties(properties);
    for (Class<?> entityClass : entities()) {
        configuration.addAnnotatedClass(entityClass);
    }
    String[] packages = packages();
    if (packages != null) {
        for (String scannedPackage : packages) {
            configuration.addPackage(scannedPackage);
        }
    }
    String[] resources = resources();
    if (resources != null) {
        for (String resource : resources) {
            configuration.addResource(resource);
        }
    }
    Interceptor interceptor = interceptor();
    if (interceptor != null) {
        configuration.setInterceptor(interceptor);
    }

    final List<Type> additionalTypes = additionalTypes();
    if (additionalTypes != null) {
        configuration.registerTypeContributor(new TypeContributor() {
            @Override
            public void contribute(TypeContributions typeContributions, ServiceRegistry serviceRegistry) {
                for (Type type : additionalTypes) {
                    if (type instanceof BasicType) {
                        typeContributions.contributeType((BasicType) type);
                    } else if (type instanceof UserType) {
                        typeContributions.contributeType((UserType) type);
                    } else if (type instanceof CompositeUserType) {
                        typeContributions.contributeType((CompositeUserType) type);
                    }
                }
            }
        });
    }
    return configuration.buildSessionFactory(
            new StandardServiceRegistryBuilder()
                    .applySettings(properties)
                    .build()
    );
}
 
Example 12
Source File: AbstractTest.java    From high-performance-java-persistence with Apache License 2.0 4 votes vote down vote up
private SessionFactory newLegacySessionFactory() {
    Properties properties = properties();
    Configuration configuration = new Configuration().addProperties(properties);
    for(Class<?> entityClass : entities()) {
        configuration.addAnnotatedClass(entityClass);
    }
    String[] packages = packages();
    if(packages != null) {
        for(String scannedPackage : packages) {
            configuration.addPackage(scannedPackage);
        }
    }
    String[] resources = resources();
    if (resources != null) {
        for (String resource : resources) {
            configuration.addResource(resource);
        }
    }
    Interceptor interceptor = interceptor();
    if(interceptor != null) {
        configuration.setInterceptor(interceptor);
    }

    final List<Type> additionalTypes = additionalTypes();
    if (additionalTypes != null) {
        configuration.registerTypeContributor((typeContributions, serviceRegistry) -> {
            additionalTypes.stream().forEach(type -> {
                if(type instanceof BasicType) {
                    typeContributions.contributeType((BasicType) type);
                } else if (type instanceof UserType ){
                    typeContributions.contributeType((UserType) type);
                } else if (type instanceof CompositeUserType) {
                    typeContributions.contributeType((CompositeUserType) type);
                }
            });
        });
    }
    return configuration.buildSessionFactory(
            new StandardServiceRegistryBuilder()
                    .applySettings(properties)
                    .build()
    );
}