Announcement Announcement Module
Collapse

JavaConfig forum decommissioned in favor of Core Container

As described at

http://static.springsource.org/sprin...fig/README.TXT

key features of the Spring JavaConfig project have been migrated into the core Spring Framework as of version 3.0.

Please see the Spring 3.0 documentation on @Configuration and @Bean support:

http://static.springsource.org/sprin...tml#beans-java

For any questions related to @Configuration classes and @Bean methods in Spring 3.0, please post in the dedicated 'Core Container' forum at

http://forum.springsource.org/forumdisplay.php?f=26
See more
See less
Trouble with Hibernate configuration Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Trouble with Hibernate configuration

    This does not work, and I don't know why. Does anything look fishy?
    Of note, I verified that the dataSource is getting created and passed to this method intact:

    Code:
        @Bean
        public SessionFactory hibernateSessionFactory() {
    
            AnnotationSessionFactoryBean factoryBean = new AnnotationSessionFactoryBean();
    
            //Set data source
            factoryBean.setDataSource(dataSource);
            
            //Add annotated classes here
            List<Class> annotatedClassList = new ArrayList<Class>();
            annotatedClassList.add(MyAnnotatedDAO.class);
            Class[] annotatedClassArray = new Class[annotatedClassList.size()];
            annotatedClassList.toArray(annotatedClassArray);
            factoryBean.setAnnotatedClasses(annotatedClassArray);
            
            //Set properties for Hibernate
            Properties hibernateProperties = new Properties();
            //SQL dialect
            hibernateProperties.put("hibernate.dialect", "org.hibernate.dialect.HSQLDialect");
            //Set the properties
            factoryBean.setHibernateProperties(hibernateProperties);
            
            //Create the session factory
            SessionFactory hibernateSessionFactory = (SessionFactory) factoryBean.getObject();
    
        }

    Also, this version works in my xml configuration:

    Code:
      <bean id="hibernateSessionFactory"
          class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
        <property name="dataSource" ref="dataSource" />
        <property name="annotatedClasses">
          <list>
            <value>com.myorg.path.security.MyAnnotatedDAO</value>
          </list>
        </property>
        <property name="hibernateProperties">
          <props>
            <prop key="hibernate.dialect">org.hibernate.dialect.HSQLDialect</prop>
          </props>
        </property>
      </bean>
    Any ideas?

  • #2
    What "does not work" about it? What's the behavior you're observing?

    At any rate, it'll probably be rectified by simply calling

    Code:
    factoryBean.afterPropertiesSet();
    SessionFactory sessionFactory = (SessionFactory) factoryBean.getObject();
    return sessionFactory;
    AnnotationSessionFactoryBean implements Spring's InitializingBean interface, and thus per contract must have the afterPropertiesSet() method called before invoking getObject().

    Comment

    Working...
    X