Eclipse RCP+Spring+EMF+Teneo

One issue for using these technologies together is using spring and the teneo HbSessionDataStore versus the LocalSessionFactoryBean that is seen in most spring tutorials.

To use the teneo approach, you need to define your beans and DAOs like the following:

<!-- Should get persistence properties and hibernate properties from property files. -->
    <bean id="sessionFactory" scope="singleton" lazy-init="true"
        class="org.eclipse.emf.teneo.hibernate.HbSessionDataStore"
        p:name="MyDataStore">
        <property name="EPackageClasses">
            <util:list>
                <value>org.yourmodel.impl.YourPackageImpl</value>
                <value>org.yourmodel2.impl.Your2PackageImpl</value>
            </util:list>
        </property>
    </bean>
   
    <util:constant static-field="org.yourmodel.YourFactory.eINSTANCE"/>
    <bean id="contactDao" scope="singleton" lazy-init="true"
        factory-bean="org.yourmodel.YourFactory.eINSTANCE"
        factory-method="createDao"
        p:sessionFactory-ref="sessionFactory"/>
    <bean id="transactionManager"
        class="org.springframework.orm.hibernate3.HibernateTransactionManager">
        <property name="sessionFactory" ref="sessionFactory" />
    </bean>
You can access the eINSTANCE through the interface directly. There are other methods to get access to the instance and give it a shorter bean name using FieldRetrievingFactoryBean (or something like that). Do not forget your namespace definitions on the beans element.

Another way to create beans, especially if you have alot of them, is to create your own spring context local copy of the factory using

<bean id="yourFactory"
class="yourPackage.impl.MyFactoryImpl"
factory-method="init">


And then use

<bean id="yourNewBean" factory-bean="yourFactory" factory-method="createYourBean" />

where createYourBean is following the creator approach implemented by EMF.

Comments

Popular posts from this blog

quick note on scala.js, react hooks, monix, auth

zio environment and modules pattern: zio, scala.js, react, query management

user experience, scala.js, cats-effect, IO