コード例 #1
0
  public void testXmlOverride() {
    AnnotationConfiguration config = new AnnotationConfiguration();
    config.addAnnotatedClass(Customer5.class);
    config.addAnnotatedClass(Order.class);
    config.addAnnotatedClass(Country.class);
    InputStream is =
        Thread.currentThread()
            .getContextClassLoader()
            .getResourceAsStream("org/hibernate/test/annotations/fetchprofile/mappings.hbm.xml");
    config.addInputStream(is);
    SessionFactoryImplementor sessionImpl =
        (SessionFactoryImplementor)
            config.buildSessionFactory(serviceRegistryHolder.getServiceRegistry());

    assertTrue(
        "fetch profile not parsed properly",
        sessionImpl.containsFetchProfileDefinition("orders-profile"));

    // now the same with no xml
    config = new AnnotationConfiguration();
    config.addAnnotatedClass(Customer5.class);
    config.addAnnotatedClass(Order.class);
    config.addAnnotatedClass(Country.class);
    try {
      config.buildSessionFactory(serviceRegistryHolder.getServiceRegistry());
      fail();
    } catch (MappingException e) {
      log.trace("success");
    }
  }
コード例 #2
0
  public void testFetchProfileConfigured() {
    AnnotationConfiguration config = new AnnotationConfiguration();
    config.addAnnotatedClass(Customer.class);
    config.addAnnotatedClass(Order.class);
    config.addAnnotatedClass(SupportTickets.class);
    config.addAnnotatedClass(Country.class);
    SessionFactoryImplementor sessionImpl =
        (SessionFactoryImplementor)
            config.buildSessionFactory(serviceRegistryHolder.getServiceRegistry());

    assertTrue(
        "fetch profile not parsed properly",
        sessionImpl.containsFetchProfileDefinition("customer-with-orders"));
    assertFalse(
        "package info should not be parsed",
        sessionImpl.containsFetchProfileDefinition("package-profile-1"));
  }
コード例 #3
0
  public void testPackageConfiguredFetchProfile() {
    AnnotationConfiguration config = new AnnotationConfiguration();
    config.addAnnotatedClass(Customer.class);
    config.addAnnotatedClass(Order.class);
    config.addAnnotatedClass(SupportTickets.class);
    config.addAnnotatedClass(Country.class);
    config.addPackage(Customer.class.getPackage().getName());
    SessionFactoryImplementor sessionImpl =
        (SessionFactoryImplementor)
            config.buildSessionFactory(serviceRegistryHolder.getServiceRegistry());

    assertTrue(
        "fetch profile not parsed properly",
        sessionImpl.containsFetchProfileDefinition("package-profile-1"));
    assertTrue(
        "fetch profile not parsed properly",
        sessionImpl.containsFetchProfileDefinition("package-profile-2"));
  }