Package org.hibernate.cfg

Examples of org.hibernate.cfg.AnnotationConfiguration


            ClassNameLocator classNameLocator)
    {
        ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
        long startTime = System.currentTimeMillis();

        AnnotationConfiguration configuration = new AnnotationConfiguration();

        // Perform normal configuration.

        configuration.configure();

        for (String packageName : packageNames)
        {
            configuration.addPackage(packageName);

            for (String className : classNameLocator.locateClassNames(packageName))
            {
                try
                {
                    Class entityClass = contextClassLoader.loadClass(className);

                    configuration.addAnnotatedClass(entityClass);
                }
                catch (ClassNotFoundException ex)
                {
                    throw new RuntimeException(ex);
                }
            }
        }

        long configurationComplete = System.currentTimeMillis();

        _sessionFactory = configuration.buildSessionFactory();

        long factoryCreated = System.currentTimeMillis();

        log.info(HibernateMessages.startupTiming(configurationComplete - startTime, factoryCreated
                - startTime));
View Full Code Here


  //We have to put the instantiation of AnnotationConfiguration
  //in a separate method. Otherwise, it will be loaded even if
  //isJava5 is false
  /*private*/ static SessionFactory java5Factory(String resource) {
    return resource == null ?
      new AnnotationConfiguration().configure().buildSessionFactory() :
      new AnnotationConfiguration().configure(resource).buildSessionFactory();
 
View Full Code Here

   * Reads metadata from annotated classes and packages into the
   * AnnotationConfiguration instance.
   */
  @Override
  protected void postProcessMappings(Configuration config) throws HibernateException {
    AnnotationConfiguration annConfig = (AnnotationConfiguration) config;
    if (this.annotatedClasses != null) {
      for (Class annotatedClass : this.annotatedClasses) {
        annConfig.addAnnotatedClass(annotatedClass);
      }
    }
    if (this.annotatedPackages != null) {
      for (String annotatedPackage : this.annotatedPackages) {
        annConfig.addPackage(annotatedPackage);
      }
    }
    scanPackages(annConfig);
  }
View Full Code Here

   * <p>Calls <code>postProcessAnnotationConfiguration</code> afterwards,
   * to give subclasses the chance to perform custom post-processing.
   * @see #postProcessAnnotationConfiguration
   */
  protected final void postProcessConfiguration(Configuration config) throws HibernateException {
    AnnotationConfiguration annConfig = (AnnotationConfiguration) config;

    if (this.annotatedClasses != null) {
      for (int i = 0; i < this.annotatedClasses.length; i++) {
        annConfig.addAnnotatedClass(this.annotatedClasses[i]);
      }
    }
    if (this.annotatedPackages != null) {
      for (int i = 0; i < this.annotatedPackages.length; i++) {
        annConfig.addPackage(this.annotatedPackages[i]);
      }
    }

    // Perform custom post-processing in subclasses.
    postProcessAnnotationConfiguration(annConfig);
View Full Code Here

  /**
   * Reads metadata from annotated classes and packages into the
   * AnnotationConfiguration instance.
   */
  protected void postProcessMappings(Configuration config) throws HibernateException {
    AnnotationConfiguration annConfig = (AnnotationConfiguration) config;
    if (this.annotatedClasses != null) {
      for (int i = 0; i < this.annotatedClasses.length; i++) {
        annConfig.addAnnotatedClass(this.annotatedClasses[i]);
      }
    }
    if (this.annotatedPackages != null) {
      for (int i = 0; i < this.annotatedPackages.length; i++) {
        annConfig.addPackage(this.annotatedPackages[i]);
      }
    }
    scanPackages(annConfig);
  }
View Full Code Here

  /** @return
   * @throws HibernateException */
  @SuppressWarnings("deprecation")
  private static SessionFactory configureSessionFactory() throws HibernateException {
   
    AnnotationConfiguration annotationConfiguration = new AnnotationConfiguration();
    annotationConfiguration.addAnnotatedClass(OnyazilarDAO.class);
    annotationConfiguration.addAnnotatedClass(BucakDAO.class);
    annotationConfiguration.addAnnotatedClass(FirmalarAnaDAO.class);
    annotationConfiguration.addAnnotatedClass(FirmalarSubelerAnaDAO.class);
    annotationConfiguration.addAnnotatedClass(FirmalarSubelerTelefonDAO.class);
    annotationConfiguration.addAnnotatedClass(FirmalarTelefonDAO.class);
    annotationConfiguration.addAnnotatedClass(KontakKisilerAnaDAO.class);
    annotationConfiguration.addAnnotatedClass(KontakKisilerTelefonDAO.class);
    annotationConfiguration.addAnnotatedClass(KosullarDAO.class);
    annotationConfiguration.addAnnotatedClass(SehirDAO.class);
    annotationConfiguration.addAnnotatedClass(SozlesmelerDAO.class);
    annotationConfiguration.addAnnotatedClass(TeslimatSartlariDAO.class);
    annotationConfiguration.addAnnotatedClass(UlkeDAO.class);
    annotationConfiguration.addAnnotatedClass(UrunlerAnaDAO.class);
    annotationConfiguration.addAnnotatedClass(UrunlerExtraDAO.class);
    annotationConfiguration.configure("hibernate.cfg.xml");
  //  new SchemaExport(annotationConfiguration).create(true,true);
   
    Configuration configuration = new Configuration();
    configuration.configure();
    sessionFactory = configuration.buildSessionFactory();
View Full Code Here

import org.hibernate.cfg.AnnotationConfiguration;

public class Test2 {
  public static void main(String[] args) throws Exception {

    AnnotationConfiguration annotationConfiguration = new AnnotationConfiguration();
    annotationConfiguration.configure("/hibernate.cfg.xml");
    Class c = Student.class;
    Annotation[] annotations = c.getAnnotations();
    for (Annotation annotation : annotations) {
      System.out.println(annotation);
    }
View Full Code Here

   * TODO
   * Among other things this test case fails because the TrafficLightModel class contains a member of type java.util.Observer which cannot be persisted by hibernate properly.
   */
  @Test
  public void testHibernateAnnotationParser () {
    AnnotationConfiguration config = new AnnotationConfiguration();
    SessionFactory sessionFactory = config.configure("hibernate.cfg.xml")
    .buildSessionFactory();
    Session s = sessionFactory.getCurrentSession();
    Assert.assertNotNull(s);
  }
View Full Code Here

  public void checkDatabaseConnection() {
    if (DATABASE_DISABLED)
      return;
    DatabaseAccess dba = DatabaseAccess.getInstance();

    AnnotationConfiguration config = new AnnotationConfiguration();
    config.setProperty("hibernate.connection.url", "jdbc:postgresql://"
        + DB_URL + ":" + DB_PORT + "/" + DB_NAME);
    config.setProperty("hibernate.connection.username", DB_USER);
    config.setProperty("hibernate.connection.password", DB_PW);
   
    SessionFactory sessionFactory = config.configure("hibernate.cfg.xml")
        .buildSessionFactory();
    Session s = sessionFactory.getCurrentSession();

    Transaction tx = null;
    try {
View Full Code Here

   
    this.dbUsername = dbUsername;
   
    this.dbPassword = dbPassword; 
   
    hibernateConfig = new AnnotationConfiguration();
    hibernateConfig.setProperty("hibernate.connection.url", "jdbc:postgresql://" + this.dbURL + ":" + this.dbPort + "/" + this.dbName);
    hibernateConfig.setProperty("hibernate.connection.username", this.dbUsername);
    hibernateConfig.setProperty("hibernate.connection.password", this.dbPassword);
   
    this.sessionFactory = hibernateConfig.configure().buildSessionFactory();
View Full Code Here

TOP

Related Classes of org.hibernate.cfg.AnnotationConfiguration

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.