Skip to content

Instantly share code, notes, and snippets.

@mmalmeida
Created October 10, 2012 16:21
Show Gist options
  • Select an option

  • Save mmalmeida/3866680 to your computer and use it in GitHub Desktop.

Select an option

Save mmalmeida/3866680 to your computer and use it in GitHub Desktop.
spring issue when upgrading to hibernate 4
package persist.integration.audit;
import persist.integration.hibernateentities.CodeIntegrationTest;
import org.hibernate.SessionFactory;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.transaction.TransactionConfiguration;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(inheritLocations=false,locations={
"/hibernate/spring-SF-tests.xml",
"/hibernate/spring-transaction.xml",
"/hibernate/testBeans.xml"
,"/hibernate/spring-audit.xml",
"/hibernate/iwrs-mail-beans-test.xml",
"/hibernate/fake-audit-meaning.xml"
})
@TransactionConfiguration(transactionManager="txManager", defaultRollback=true)
public class CodeAuditIntegrationTest extends CodeIntegrationTest {
@Autowired
private SessionFactory auditFactory;
@Before
public void cleanAudit(){
auditFactory.getCurrentSession().createQuery("delete from AuditLogRecord").executeUpdate();
}
@Test
public void clinicalTrialAssociationTest() {
super.clinicalTrialAssociationTest();
}
}
-----------------------XML--------------------
<bean id="txManager"
class="org.springframework.orm.hibernate4.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<tx:annotation-driven transaction-manager="txManager" />
<bean id="sessionFactory" scope="singleton"
class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="hibernateProperties">
<props>
<prop key="hibernate.hbm2ddl.auto">${hibernate.hbm2dll}</prop>
<prop key="hibernate.hbm2ddl.import_files">${hibernate.sql_scripts}</prop>
</props>
</property>
<property name="packagesToScan">...</property>
<property name="annotatedPackages">...</property>
<property name="mappingLocations">...</property>
<property name="dataSource" ref="c3p0DataSource" />
<property name="entityInterceptor" ref="auditInterceptor" />
</bean>
<bean id="auditFactory" scope="singleton"
class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="exposeTransactionAwareSessionFactory"> -->needs to be removed in hibernate4!
<value>true</value>
</property>
<property name="mappingLocations">...</property>
<property name="packagesToScan">...</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.hbm2ddl.auto">${hibernate.hbm2dll}</prop>
</props>
</property>
<property name="dataSource" ref="c3p0DataSource" />
</bean>
@fayaz47

fayaz47 commented Jan 29, 2016

Copy link
Copy Markdown

Is it compulsory to use annotations in hibernate?.

Actually in our project we are not using annotations. Can we upgrade the project to hibernate 4. I resolved the all the compilation issue. But when i do real time testing dao's are not loading . I don't know what happend. Can anybody help on this.
I am overriding the setmappingresources(String... resources) method from the localsessionfactorybean class of hiberate4. Please help me in this area. How to load the mappingsources?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment