org.hibernate.cfg.Configuration.addClass()方法的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(7.5k)|赞(0)|评价(0)|浏览(212)

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

Configuration.addClass介绍

[英]Read a mapping as an application resource using the convention that a class named foo.bar.Foo is mapped by a file foo/bar/Foo.hbm.xml which can be resolved as a classpath resource.
[中]使用名为foo的类的约定将映射作为应用程序资源读取。酒吧Foo由文件Foo/bar/Foo映射。哈佛商学院。可以解析为类路径资源的xml。

代码示例

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

@Test
public void testHbmWithSubclassExtends() throws Exception {
  Configuration cfg = new Configuration();
  cfg.configure( "org/hibernate/test/annotations/hibernate.cfg.xml" );
  cfg.addClass( Ferry.class );
  cfg.setProperty( Environment.HBM2DDL_AUTO, "create-drop" );
  SessionFactory sf = cfg.buildSessionFactory();
  assertNotNull( sf );
  Session s = sf.openSession();
  Transaction tx = s.beginTransaction();
  Query q = s.createQuery( "from Ferry" );
  assertEquals( 0, q.list().size() );
  q = s.createQuery( "from Plane" );
  assertEquals( 0, q.list().size() );
  tx.commit();
  s.close();
  sf.close();
}
 @Test

代码示例来源:origin: org.hibernate/hibernate-annotations

@Override
public AnnotationConfiguration addClass(Class persistentClass) throws MappingException {
  super.addClass( persistentClass );
  return this;
}

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

cfg.addClass( InvalidMapping.class );
fail();

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

cfg.addClass( Hibernate.class ); // TODO: String.class result in npe, because no classloader exists for it
fail();

代码示例来源:origin: org.hibernate/com.springsource.org.hibernate

@Override
public AnnotationConfiguration addClass(Class persistentClass) throws MappingException {
  super.addClass( persistentClass );
  return this;
}

代码示例来源:origin: org.hibernate/com.springsource.org.hibernate.core

@Override
public AnnotationConfiguration addClass(Class persistentClass) throws MappingException {
  super.addClass( persistentClass );
  return this;
}

代码示例来源:origin: babyfish-ct/babyfish

@SuppressWarnings("rawtypes")
@Override
public Configuration addClass(Class persistentClass)
    throws MappingException {
  super.addClass(persistentClass);
  return this;
}

代码示例来源:origin: org.wso2.bpel/ode-bpel-store

static Configuration getDefaultConfiguration() throws MappingException {
  return new Configuration().addClass(ProcessConfDaoImpl.class).addClass(DeploymentUnitDaoImpl.class)
      .addClass(VersionTrackerDAOImpl.class);
}

代码示例来源:origin: dkpro/dkpro-jwpl

private static Configuration getConfiguration(DatabaseConfiguration config) {
    Configuration cfg = new Configuration()
    .addClass(Category.class)
    .addClass(MetaData.class)
    .addClass(Page.class)
    .addClass(PageMapLine.class)
//        .addClass(RelatednessCacheLine.class)
    .addProperties(getProperties(config));
    return cfg;
  }

代码示例来源:origin: org.hibernate/com.springsource.org.hibernate.ejb

public Ejb3Configuration addClass(Class persistentClass) throws MappingException {
  Thread thread = null;
  ClassLoader contextClassLoader = null;
  if (overridenClassLoader != null) {
    thread = Thread.currentThread();
    contextClassLoader = thread.getContextClassLoader();
    thread.setContextClassLoader( overridenClassLoader );
  }
  try {
    cfg.addClass( persistentClass );
    return this;
  }
  finally {
    if (thread != null) thread.setContextClassLoader( contextClassLoader );
  }
}

代码示例来源:origin: phenotips/phenotips

@Override
  public void onEvent(Event event, Object source, Object data)
  {
    this.sessionFactory.getConfiguration().addClass(EncryptedProperty.class);
  }
}

代码示例来源:origin: org.phenotips/phenotips-crypto-xproperty

@Override
  public void onEvent(Event event, Object source, Object data)
  {
    this.sessionFactory.getConfiguration().addClass(EncryptedProperty.class);
  }
}

代码示例来源:origin: qos-ch/logback-audit

static public Configuration createConfiguration() {
 final Configuration cfg = new Configuration();
 // Configure Hibernate mappings,this will look for the "hbm.xml" resources.
 // In alphabetical order:
 cfg.addClass(AuditEvent.class);
 return cfg;
}

代码示例来源:origin: org.ow2.bonita/bonita-pvm

public void apply(Object target, WireContext wireContext) {
 Configuration configuration = (Configuration) target;
 try {
  Class<?> persistentClass = wireContext.getClassLoader().loadClass(
    className);
  configuration.addClass(persistentClass);
 } catch (Exception e) {
  throw new PvmException("couldn't add mapping for class " + className, e);
 }
}

代码示例来源:origin: org.jbpm/pvm

public void apply(Object target, WireContext wireContext) {
 Configuration configuration = (Configuration) target;
 try {
  Class<?> persistentClass = wireContext.getClassLoader().loadClass(className);
  configuration.addClass(persistentClass);
 } catch (Exception e) {
  throw new PvmException("couldn't add mapping for class "+className, e);
 }
}
public String toString() {

代码示例来源:origin: com.atlassian.osuser/osuser-provider-hibernate3

configuration.addClass(HibernateGroup.class);
configuration.addClass(HibernateUser.class);
configuration.addClass(PropertySetItem.class);

代码示例来源:origin: org.nuiton.topia/topia-persistence

public Metadata newMetaData(Configuration configuration, SessionFactory sessionFactory, Collection<Class<?>> entityClasses) {

    StandardServiceRegistry standardServiceRegistry = getStandardServiceRegistry(sessionFactory);
    MetadataSources sources = new MetadataSources(standardServiceRegistry);
    for (Class<?> persistanceClass : entityClasses) {
      String hbmXmlFile = persistanceClass.getName().replace('.', '/') + ".hbm.xml";
      sources.addResource(hbmXmlFile);
      configuration.addClass(persistanceClass);
    }

    MetadataBuilder metadataBuilder = sources.getMetadataBuilder();

    return metadataBuilder.build();
  }
}

代码示例来源:origin: org.ow2.bonita/bonita-server

@Override
public void apply(final Object target, final WireContext wireContext) {
 final Configuration configuration = (Configuration) target;
 try {
  final Class<?> persistentClass = wireContext.getClassLoader().loadClass(className);
  configuration.addClass(persistentClass);
 } catch (final Exception e) {
  final String message = ExceptionManager.getInstance().getFullMessage("bp_HCD_2", className);
  throw new BonitaRuntimeException(message, e);
 }
}

代码示例来源:origin: org.nuiton.topia/topia-service-migration

/**
 * Creates the hibernate configuration to be used by the service.
 *
 * @param appContext the topia application context used to copy database credentials
 * @since 2.5.3
 */
protected static Configuration createTMSHibernateConfiguration(TopiaApplicationContext appContext) {
  TopiaConfiguration topiaConfiguration = appContext.getConfiguration();
  Properties prop = new Properties();
  prop.put(AvailableSettings.URL, topiaConfiguration.getJdbcConnectionUrl());
  prop.put(AvailableSettings.USER, topiaConfiguration.getJdbcConnectionUser());
  prop.put(AvailableSettings.PASS, topiaConfiguration.getJdbcConnectionPassword());
  prop.put(AvailableSettings.DRIVER, topiaConfiguration.getJdbcDriverClass().getName());
  prop.put(AvailableSettings.DIALECT, HibernateProvider.getHibernateDialect(topiaConfiguration));
  prop.putAll(topiaConfiguration.getHibernateExtraConfiguration());
  Configuration result = new Configuration();
  result.setProperties(prop);
  result.addClass(TMSVersion.class);
  return result;
}

代码示例来源:origin: org.ikasan/ikasan-connector-basefiletransfer

/**
 * static accessor for singleton BaseFileTransferDao
 * 
 * @return singleton instance of BaseFileTransferDao
 */
public static BaseFileTransferDao getBaseFileTransferDao() {
  if (baseFileTransferDao == null) {
    Configuration cfg = generateConfiguration();
    cfg.setProperty(Environment.DATASOURCE,
        "java:/datasource/ikasan/xads");
    cfg.addClass(FileFilter.class); // this will expect to find
                    // FileFilter.hbm.xml in the fully
                    // qualified package for FileFilter
    SessionFactory baseFileTrasferHibernateSessionFactory = cfg
        .buildSessionFactory();
    baseFileTransferDao = new HibernateBaseFileTransferDaoImpl(
        baseFileTrasferHibernateSessionFactory);
  }
  return baseFileTransferDao;
}

相关文章

Configuration类方法