Fornax-Platform
Forum

 « Return to Thread: Defining Datasource Properties.

Re: Defining Datasource Properties.

by deepshar027 :: Rate this Message:

Reply to Author | View in Thread

Patrik,

Thanks for that.I have a new problem now which is not related to this thread.
Actually I deleted all my sources from src\generated\resources so that they can be generated again when I run the workflow.

However when I run the workflow again , I dont see SessionFactory.xml ? I guess earlier I was using sculptor version 1.5 and then switched to 1.6 .Is SessionFactory.xml not generated for 1.6?
If its not generated then where should be the datasource defined?

Let me know if there is any documentation available for details on various sources generated.


Rgds,
Deepak.

Patrik Nordwall wrote:
Three alternatives

Alternative 1.
You can define your own sessionFactory and datasource bean in more.xml
These will be used instead of the generated SesssionFactory.xml
If you find it confusing to have the sessionFactory bean defined in two places you can replace the the code generation like this...

Alternative 2.
To simply skip generation of SessionFactory.xml, and define it manually in src/main/resources you could can add this to SpecialCases.xpt:
«AROUND templates::Spring::sessionFactory FOR Application»
«ENDAROUND»

Alternative 3.
If you prefer to generate SessionFactory.xml with your own definition.
In SpecialCases.xpt:

«IMPORT sculptormetamodel»
«EXTENSION extensions::helper»
«EXTENSION extensions::properties»

«AROUND templates::Spring::sessionFactory FOR Application»
        «EXPAND mySessionFactory»
«ENDAROUND»

«DEFINE mySessionFactory FOR Application»
«FILE getResourceDir("spring") + getApplicationContextFile("SessionFactory.xml") TO_GEN_RESOURCES-»
«EXPAND templates::Spring::header»
        «IF isWar() -»
      «EXPAND templates::Spring::txManager»
    «ENDIF -»
   
    «IF isJpaAnnotationToBeGenerated()»
    <bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
        <property name="dataSource" ref="myDataSource"/>
                <property name="configLocation" value="hibernate.cfg.xml"></property>
        «ELSE»
    <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
        <property name="dataSource">
            <ref bean="myDataSource" />
        </property>
        «EXPAND templates::Spring::hibernateMappingResources»
        «ENDIF»

        <property name="entityInterceptor">
            <ref bean="auditInterceptor" />
        </property>
    </bean>
    <bean id="auditInterceptor" class="«auditInterceptorClass()»"/>

</beans>
«ENDFILE»
«ENDDEFINE»


Add myDataSource in more.xml


Using this technique it is possible to change the generated output of most things.
You need to look in the source code of the code generation templates to know what AROUNDs that can be done. Above is from Spring.xpt

/Patrik

 « Return to Thread: Defining Datasource Properties.