Package org.hibernate.cfg

Examples of org.hibernate.cfg.AnnotationConfiguration


    s.close();
  }
 
  public void testMiscplacedImmutableAnnotation() {
    try {
      AnnotationConfiguration config = new AnnotationConfiguration();
      config.addAnnotatedClass(Foobar.class);
      config.buildSessionFactory();
      fail();
    } catch (AnnotationException ae) {
      log.debug("succes");
    }
  }
View Full Code Here


  public SecuredBindingTest(String x) {
    super( x );
  }

  public void testConfigurationMethods() throws Exception {
    AnnotationConfiguration ac = new AnnotationConfiguration();
    Properties p = new Properties();
    p.put( Environment.DIALECT, "org.hibernate.dialect.HSQLDialect" );
    p.put( "hibernate.connection.driver_class", "org.hsqldb.jdbcDrive" );
    p.put( "hibernate.connection.url", "jdbc:hsqldb:." );
    p.put( "hibernate.connection.username", "sa" );
    p.put( "hibernate.connection.password", "" );
    p.put( "hibernate.show_sql", "true" );
    ac.setProperties( p );
    ac.addAnnotatedClass( Plane.class );
    SessionFactory sf;
    try {
      sf = ac.buildSessionFactory();
      fail( "Driver property overriding should work" );
      sf.close();
    }
    catch (HibernateException he) {
      //success
View Full Code Here

/**
* @author Emmanuel Bernard
*/
public class DuplicateTest extends TestCase {
  public void testDuplicateEntityName() throws Exception {
    AnnotationConfiguration cfg = new AnnotationConfiguration();
    cfg.setProperty( Environment.HBM2DDL_AUTO, "create-drop" );
    try {
      cfg.addAnnotatedClass( Flight.class );
      cfg.addAnnotatedClass( org.hibernate.test.annotations.Flight.class );
      cfg.addResource( "org/hibernate/test/annotations/orm.xml" );
      cfg.addResource( "org/hibernate/test/annotations/duplicatedgenerator/orm.xml" );
      cfg.buildSessionFactory();
      fail( "Should not be able to map the same entity name twice" );
    }
    catch (AnnotationException ae) {
      //success
    }
View Full Code Here

/**
* @author Emmanuel Bernard
*/
public class ConfigurationTest extends junit.framework.TestCase {
  public void testDeclarativeMix() throws Exception {
    AnnotationConfiguration cfg = new AnnotationConfiguration();
    cfg.configure( "org/hibernate/test/annotations/hibernate.cfg.xml" );
    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 Boat" );
    assertEquals( 0, q.list().size() );
View Full Code Here

    s.close();
    sf.close();
  }

  public void testIgnoringHbm() throws Exception {
    AnnotationConfiguration cfg = new AnnotationConfiguration();
    cfg.configure( "org/hibernate/test/annotations/hibernate.cfg.xml" );
    cfg.setProperty( Environment.HBM2DDL_AUTO, "create-drop" );
    cfg.setProperty( AnnotationConfiguration.ARTEFACT_PROCESSING_ORDER, "class" );
    SessionFactory sf = cfg.buildSessionFactory();
    assertNotNull( sf );
    Session s = sf.openSession();
    Transaction tx = s.beginTransaction();
    Query q;
    try {
View Full Code Here

    s.close();
    sf.close();
  }

  public void testPrecedenceHbm() throws Exception {
    AnnotationConfiguration cfg = new AnnotationConfiguration();
    cfg.configure( "org/hibernate/test/annotations/hibernate.cfg.xml" );
    cfg.setProperty( Environment.HBM2DDL_AUTO, "create-drop" );
    cfg.addAnnotatedClass( Boat.class );
    SessionFactory sf = cfg.buildSessionFactory();
    assertNotNull( sf );
    Session s = sf.openSession();
    s.getTransaction().begin();
    Boat boat = new Boat();
    boat.setSize( 12 );
View Full Code Here

    s.close();
    sf.close();
  }

  public void testPrecedenceAnnotation() throws Exception {
    AnnotationConfiguration cfg = new AnnotationConfiguration();
    cfg.configure( "org/hibernate/test/annotations/hibernate.cfg.xml" );
    cfg.setProperty( Environment.HBM2DDL_AUTO, "create-drop" );
    cfg.setProperty( AnnotationConfiguration.ARTEFACT_PROCESSING_ORDER, "class, hbm" );
    cfg.addAnnotatedClass( Boat.class );
    SessionFactory sf = cfg.buildSessionFactory();
    assertNotNull( sf );
    Session s = sf.openSession();
    s.getTransaction().begin();
    Boat boat = new Boat();
    boat.setSize( 12 );
View Full Code Here

    s.close();
    sf.close();
  }

  public void testHbmWithSubclassExtends() throws Exception {
    AnnotationConfiguration cfg = new AnnotationConfiguration();
    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() );
View Full Code Here

    s.close();
    sf.close();
  }

  public void testAnnReferencesHbm() throws Exception {
    AnnotationConfiguration cfg = new AnnotationConfiguration();
    cfg.configure( "org/hibernate/test/annotations/hibernate.cfg.xml" );
    cfg.addAnnotatedClass( Port.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 Boat" );
    assertEquals( 0, q.list().size() );
View Full Code Here

/**
* @author Emmanuel Bernard
*/
public class SafeMappingTest extends junit.framework.TestCase {
  public void testDeclarativeMix() throws Exception {
    AnnotationConfiguration cfg = new AnnotationConfiguration();
    cfg.addAnnotatedClass( IncorrectEntity.class );
    cfg.setProperty( Environment.HBM2DDL_AUTO, "create-drop" );
    try {
      SessionFactory sf = cfg.buildSessionFactory();
      fail( "Entity wo id should fail" );
    }
    catch (AnnotationException e) {
      //success
    }
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.