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"); } }
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")); }
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")); }