本文整理汇总了Java中org.hibernate.cfg.Configuration.addPackage方法的典型用法代码示例。如果您正苦于以下问题:Java Configuration.addPackage方法的具体用法?Java Configuration.addPackage怎么用?Java Configuration.addPackage使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.hibernate.cfg.Configuration
的用法示例。
在下文中一共展示了Configuration.addPackage方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: postProcessMappings
import org.hibernate.cfg.Configuration; //导入方法依赖的package包/类
/**
* 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);
}
示例2: newSessionFactory
import org.hibernate.cfg.Configuration; //导入方法依赖的package包/类
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()
);
}
示例3: DataManager
import org.hibernate.cfg.Configuration; //导入方法依赖的package包/类
public DataManager(Config config) throws ServerException {
// Disable hibernate logging
@SuppressWarnings("unused")
org.jboss.logging.Logger logger = org.jboss.logging.Logger.getLogger("org.hibernate");
java.util.logging.Logger.getLogger("org.hibernate").setLevel(java.util.logging.Level.WARNING);
// Disable c3p0 logging
Properties p = new Properties(System.getProperties());
p.put("com.mchange.v2.log.MLog", "com.mchange.v2.log.FallbackMLog");
p.put("com.mchange.v2.log.FallbackMLog.DEFAULT_CUTOFF_LEVEL", "WARNING");
System.setProperties(p);
Properties properties = new Properties();
properties.setProperty("hibernate.show_sql", config.get("database.show_sql").getAsBoolean() ? "true" : "false");
switch (config.get("database.provider").getAsString()) {
case "mysql":
properties.setProperty("hibernate.dialect", "org.hibernate.dialect.MySQL57Dialect");
properties.setProperty("hibernate.connection.driver_class", "com.mysql.jdbc.Driver");
properties.setProperty("hibernate.connection.CharSet", "utf8");
properties.setProperty("hibernate.connection.characterEncoding", "utf8");
properties.setProperty("hibernate.connection.useUnicode", "true");
properties.setProperty("hibernate.connection.url", (new StringBuilder())
.append("jdbc:mysql://")
.append(config.get("database.mysql.host").getAsString())
.append(":")
.append(config.get("database.mysql.port").getAsShort())
.append("/")
.append(config.get("database.mysql.database").getAsString())
.toString());
properties.setProperty("hibernate.connection.username", config.get("database.mysql.user").getAsString());
properties.setProperty("hibernate.connection.password", config.get("database.mysql.password").getAsString());
break;
default:
throw new ServerException("Invalid data provider " + config.get("database.provider").getAsString());
}
Configuration configuration = new Configuration()
.configure()
.addProperties(properties);
configuration.addPackage("royaleserver.database.entity");
for (Class<?> clazz : (new Reflections("royaleserver.database.entity")).getTypesAnnotatedWith(Entity.class)) {
if (!Modifier.isAbstract(clazz.getModifiers())) {
configuration.addAnnotatedClass(clazz);
}
}
sessionFactory = configuration.buildSessionFactory();
services = new DataServices(sessionFactory);
}
示例4: newLegacySessionFactory
import org.hibernate.cfg.Configuration; //导入方法依赖的package包/类
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()
);
}
示例5: newSessionFactory
import org.hibernate.cfg.Configuration; //导入方法依赖的package包/类
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()
);
}
示例6: newLegacySessionFactory
import org.hibernate.cfg.Configuration; //导入方法依赖的package包/类
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()
);
}