Announcement Announcement Module
Collapse
No announcement yet.
Hibernate - using a hybrid annotation and XML config approach Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Hibernate - using a hybrid annotation and XML config approach

    Hi,
    I'm developing a new application which is based upon another old application.

    This old application uses XML for the Hibernate configuration. When I add the new functionality to the the application I want to use annotations for the Hibernate configuration.
    I don't really want to change the old code to use annotations as this will be both time consuming and error prone.
    I notice that in the Spring training it is mentioned that a hybrid approach can be adopted, but it doesn't mention how.

    How do I go about using both annotations and XML configuration in the same application? Do I need to define 2 seperate session factories in the hibernate.cfg.xml file?
    Does anyone have an example?

    Cheers,

    Nige

  • #2
    Code:
    <bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
    		<property name="dataSource">
    			<ref bean="dataSource"></ref>
    		</property>
    
    		<property name="mappingResources">
                    
                    <list>
    	        put your mapping resources here
                    </list>
                    </property>
    
    
    		<property name="annotatedClasses">
    			<list>
                  	        put your annotated classes here
    			</list>
    		</property>

    Comment


    • #3
      Thanks very much, that was great help.

      For the old xml config stuff I can also use :

      Code:
      <property name="mappingLocations"><value>classpath*:com/foo/bar/*.hbm.xml</value></property>
      Cheers,

      Nige

      Comment

      Working...
      X