I have the following spring xml configuration header:
<beans
xmlns="http://www.springframework.org/schema/beans"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:task="http://www.springframework.org/schema/task"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task.xsd">
<tx:annotation-driven transaction-manager="transactionManager"/>
....
When I open file in idea I see red errors:
1.xmlns:p="http://www.springframework.org/schema/p -
URI is not registered
Errors in idea for beans tag.
But it is working good.
How to avoid red errors ?
P.S.
I have the following fragment in my xml configuration:
<bean id="sessionFactory"
class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource"/>
<property name="configLocation">
<value>classpath:hibernate.cfg.xml</value>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.dialect">${jdbc.dialect}</prop>
<prop key="hibernate.connection.charSet">UTF-8</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.format_sql">true</prop>
<prop key="hbm2ddl.auto">validate</prop>
</props>
</property>
</bean>
One special namespace(p namespace) is not defined in an XSD file, and only exists in the core of Spring itself.
p-namespace doesn't need a schema definition and is an alternative way of configuring your properties
differently than the way you have seen so far.
Since p: "namespaces" do not have an associated XSD scheme, Intelijj is failing to validate this namespace.
One Solution is to trun off validation in IDEA, but you cant find other issues.
It seems Intelijj IDEA does not provided any solution for this issue.
https://youtrack.jetbrains.com/issue/IDEA-101723
If you remove this line of code xmlns:p="http://www.springframework.org/schema/p" from the xml then errors will be cleaned. Because there is no such xsd available in spring. Event if you want to use such xsd then you may try following code:
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"
p:dataSource-ref="dataSource"
p:mappingResources-ref="mappingResourcesList"
p:hibernateProperties-ref="hibernatePropertiesProps" />
Basically, they are defined to map to the same XML namespaces.
You're registering "p" as a namespace using a schema that doesn't exist. If you don't have any tags like <p: ></p: >, then your config will still work at runtime. However, your IDE checks to make sure all namespace definitions are correct (even if unused).
The easiest way to fix it is to remove the offending namespace definition. If you are using that namespace, find the correct location for the schema and place it there.
Related
In a Java project I'm working on I've got the following setup for our unit tests:
I'm using Spring Test MVC, #RunWith(SpringJUnit4ClassRunner.class) and #WebAppConfiguration to run the unit tests, and I create a MockMvc instance using webAppContextSetup(webApplicationContext) to test the application.
I've got a Hibernate config to set up an in-memory HSQLDB, all tables are created based on the #Entity classes.
In the Hibernate config, I'm setting the hibernate.hbm2ddl.import_files property to load a file import.sql with SQL statements to populate the (in-memory) database.
Now, I've confirmed all these above work:
Tests can successfully insert/retrieve from the in-memory DB.
The SQL statements in the import.sql are executed, as various tests confirm.
Now the problem: Errors occurring with statements I add in import.sql don't seem to be reported anywhere, neither is any indication given that an error occurred at all. Instead, subsequent statements are simply not executed. (I've confirmed this through testing.)
Is there any way or place these errors are reported that I'm apparently unaware of? Is there an additional Hibernate property for this?
Excerpt from hibernate test config:
<bean id="sessionFactory" name="mySessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="dataSource" ref="myDataSource" />
<property name="hibernateProperties">
<props>
<prop key="hibernate.archive.autodetection">class,hbm</prop>
<prop key="hibernate.dialect">org.hibernate.dialect.HSQLDialect</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.connection.driver_class">org.hsqldb.jdbcDriver</prop>
<prop key="hibernate.connection.username">sa</prop>
<prop key="hibernate.connection.password"></prop>
<prop key="hibernate.connection.url">jdbc:hsqldb:mem:myschema</prop>
<prop key="hibernate.hbm2ddl.auto">create</prop>
<prop key="hibernate.hbm2ddl.import_files">configuration/test/import.sql</prop>
<prop key="hibernate.hbm2ddl.import_files_sql_extractor">org.hibernate.tool.hbm2ddl.MultipleLinesSqlCommandExtractor</prop>
<!-- when using type="yes_no" for booleans, the line below allow booleans in HQL expressions: -->
<prop key="hibernate.query.substitutions">true 'Y', false 'N'</prop>
</props>
</property>
</bean>
I wasn't able to get exceptions to log, like #Julien Kroneg suggested.
But I was able to put a breakpoint in the catch block of the method org.hibernate.tool.hbm2ddl.SchemaExport#importScript where trimmedSql represents each SQL statement as it's being applied:
catch ( Exception e ) {
if (haltOnError) {
throw new ImportScriptException( "Error during statement execution (file: '"
+ namedReader.getName() + "'): " + trimmedSql, e );
}
exceptions.add(e);
LOG.unsuccessful(trimmedSql);
LOG.error(e.getMessage());
}
It may be enough, given how init scripts are static and not really business data, once you get them to work, they hopefully keep working.
Not really an answer to your question, but alternative way to handle test DB population.
There is a XML namespace in Spring called jdbc that allows you to prepopulate your database with initial data during Spring context startup. Also it reports errors in your SQLs just fine:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:jdbc="http://www.springframework.org/schema/jdbc"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/jdbc
http://www.springframework.org/schema/jdbc/spring-jdbc.xsd">
<jdbc:initialize-database data-source="dataSource">
<jdbc:script location="org/mytestproject/schema-drop-hsqldb.sql" />
<jdbc:script location="org/mytestproject/schema-hsqldb.sql" />
<jdbc:script location="org/mytestproject/data-hsqldb.sql" />
</jdbc:initialize-database>
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="${jdbc.driver}"/>
<property name="url" value="${jdbc.url}"/>
<property name="username" value="${jdbc.username}"/>
<property name="password" value="${jdbc.password}"/>
<property name="validationQuery" value="${jdbc.validationQuery}"/>
</bean>
</beans>
You can activate the logging on class org.hibernate.tool.hbm2ddl.SchemaExport with level TRACE.
Some errors are logged at DEBUG level (e.g. file not found):
10:29:21,039 DEBUG SchemaExport:353 - Import file not found: ../myFile.sql
I'm trying to connect dtatbase to my web application. Database in MSSQL server. Here is my applicationContext.xml file:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.1.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd">
<bean id="txManagerDH" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="dhSessionFactory"/>
</bean>
<tx:annotation-driven transaction-manager="txManagerDH"/>
<bean id="dhDataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource"
p:driverClassName="com.microsoft.sqlserver.jdbc.SQLServerDriver"
p:url="jdbc:sqlserver://TARAS-PC\SQLEXPRESS:1433:databaseName=DH:"
p:username="GlassfishDH"
p:password="glassfish" />
<bean id="dhSessionFactory"
class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean"
p:dataSource-ref="dhDataSource">
<property name="annotatedClasses">
<list>
<value>model.User</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">
org.hibernate.dialect.SQLServerDialect
</prop>
<prop key="hibernate.show_sql">false</prop>
</props>
</property>
</bean>
<bean id="UserDao" class="model.UserDao" p:sessionFactory-ref="dhSessionFactory"/>
<bean id="UserService" class="service.UserService"
p:userDao-ref="UserDao"/>
</beans>
When I'm trying run it I have an error:
Error occurred during deployment: Exception while loading the app :
java.lang.IllegalStateException: ContainerBase.addChild: start:
org.apache.catalina.LifecycleException:
org.springframework.beans.factory.BeanCreationException: Error
creating bean with name 'txManagerDH' defined in ServletContext
resource [/WEB-INF/applicationContext.xml]: BeanPostProcessor before
instantiation of bean failed; nested exception is
java.lang.NoClassDefFoundError: org/aopalliance/aop/Advice. Please see
server.log for more details.
I don't what is wrong in my code. Please help me.
You're missing the aop-alliance library from your class path. You can get the binary or the maven dependency here.
Alternatively, get the full spring-aop library.
If your facing the same problem, then you miss aopalliance.jar. Here in this location you can the load the jar http://mvnrepository.com/artifact/aopalliance/aopalliance/1.0. Also it is recommend that you use Maven to handle all these dependencies instead of doing it yourself. I faced the same issue here it is solved. Here my post : Not able to load the applicationContext.xml in Spring. If this problem is solved there would be another in compatability of spring 4.0.0 with hibernate 4.30.
In dipatcher-servlet,instead of
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
Use
<bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
I have a Spring Batch application that has a Spring context configuration that normally each batch job would reference. This way each batch job uses the same entity manager.
batch-context.xml:
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:batch="http://www.springframework.org/schema/batch"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.1.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/batch http://www.springframework.org/schema/batch/spring-batch-2.1.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd">
<!-- ... -->
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="persistenceUnitName" value="myPersistenceUnit" />
<property name="jpaVendorAdapter">
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter" />
</property>
<property name="packagesToScan" value="com.example.domain" />
<property name="jpaProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.Oracle10gDialect</prop>
<prop key="hibernate.cache.use_second_level_cache">true</prop>
<prop key="hibernate.cache.provider_class"> org.hibernate.cache.EhCacheProvider</prop>
<prop key="hibernate.max_fetch_depth">3</prop>
<prop key="hibernate.jdbc.fetch_size">100</prop>
<prop key="hibernate.jbc.batch_size">1000</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.use_sql_comments">false</prop>
</props>
</property>
</bean>
<!-- ... -->
</beans>
Now in my specific batch job context (call it ExampleBatch.xml) I want to add another package to scan to the already defined entityManagerFactory bean. Is this possible?
ExampleBatch.xml:
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:batch="http://www.springframework.org/schema/batch"
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.1.xsd
http://www.springframework.org/schema/batch http://www.springframework.org/schema/batch/spring-batch-2.1.xsd">
<!-- ... -->
<import resource="classpath:batch-context.xml" />
<bean id="entityManagerFactoryWithExtraPackages"
class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"
parent="entityManagerFactory">
<!-- How do I override the packagesToScan property on the already defined entityManagerFactory bean?-->
<property
name="packagesToScan"
value ="com.example.domain,com.example.domain.abstraction"
/>
</bean>
<!-- ... -->
</beans>
The way I have it right now will not work because it complains that "No unique bean of type [javax.persistence.EntityManagerFactory] is defined: expected single bean but found 2"
Is trying to override the "packagesToScan" property the right approach to take in this scenario? Is there a better way to accomplish this behavior?
Edit:
I was able to accomplish what I needed using the property-override functionality. Below is the updated ExampleBatch.xml that I went with
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:batch="http://www.springframework.org/schema/batch"
xmlns:util="http://www.springframework.org/schema/util"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.1.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd
http://www.springframework.org/schema/batch http://www.springframework.org/schema/batch/spring-batch-2.1.xsd">
<!-- ... -->
<import resource="classpath:batch-context.xml" />
<context:property-override properties-ref="entityManagerOverride"/>
<bean id="entityManagerOverride"
class="org.springframework.beans.factory.config.PropertiesFactoryBean">
<property name="properties">
<util:properties>
<prop key="entityManagerFactory.packagesToScan">com.example.domain,com.example.batch.module.domain</prop>
</util:properties>
</property>
</bean>
<!-- ... -->
</beans>
So far Spring does not yell at me that this is an invalid configuration. Have yet to determine if this is in fact producing the desired outcome.
Edit 2:
The property-override method does not appear to be sufficient. It is a valid configuration but after inspecting the entity manager at runtime like this:
for (EntityType<?> entity : manager.getMetamodel().getEntities()) {
String name = entity.getName();
System.out.println(name);
}
It only contains entities from the com.example.domain package.
Does anyone have any other ideas?
The way you have it now, you really define two separate beans - one called entityManagerFactory and the other one entityManagerFactoryWithExtraPackages.
There are several ways to solve your very request:
Just get rid of one of the beans - merge the definitions into one.
I only guess it's not an option for you, otherwise you wouldn't ask.
Define the entityManagerFactory as abstract, then you end up having one bean anyway.
Use the property override mechanism. This fits the scenarios, where you are not in control of the 'top' bean and despite that you want to re-configure (literally override the values of the properties of) beans defined there.
Just replace this:
<property
name="packagesToScan"
value ="com.example.domain,com.example.domain.abstraction"/>
with this:
<property name="packagesToScan">
<array>
<value>com.example.domain</value>
<value>com.example.domain.abstraction</value>
</array>
</property>
If it fits your packages organization, you may try
<property name="packagesToScan" value="com.example.domain.*" />
In your batch-context.xml, so your ExampleBatch.xml doesn't have anymore to "override" the parent.
Another way to dig is using placeholder; in batch-context.xml, you would use :
<property name="packagesToScan" value="${packageList}" />
while in ExampleBatch.xml you would declare the placeholder with the appropriate value, as explained for example here : http://www.mkyong.com/spring/spring-propertyplaceholderconfigurer-example/
I want my read methods not to use a transaction since this is just not needed at all, I only mark my create/update methods with #Transactional. But how do I do this? I have a pretty basic configuration of Spring with etc...
SessionFactory is injected in my DAO, and in each method I call sessionFactory.getCurrentSession().doQueryStuff();
This, however results in this error:
org.hibernate.HibernateException: No Hibernate Session bound to thread, and configuration does not allow creation of non-transactional one here
If you need my Spring configuration:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:oxm="http://www.springframework.org/schema/oxm"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
http://www.springframework.org/schema/oxm
http://www.springframework.org/schema/oxm/spring-oxm-3.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/util
http://www.springframework.org/schema/util/spring-util-3.0.xsd">
<context:annotation-config />
<context:component-scan base-package="be.howest.kidscalcula" />
<mvc:annotation-driven />
<bean id="viewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix">
<value>/WEB-INF/views/</value>
</property>
<property name="suffix">
<value>.jsp</value>
</property>
</bean>
<bean id="myDataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver" />
<property name="url" value="jdbc:mysql://localhost/kidscalcula" />
<property name="username" value="root" />
<property name="password" value="" />
</bean>
<bean class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"
id="sessionFactory">
<property name="dataSource" ref="myDataSource" />
<property name="mappingResources">
<list>
<value>be/howest/kidscalcula/model/Foto.hbm.xml</value>
<value>be/howest/kidscalcula/model/Kindleerplanonderdeel.hbm.xml
</value>
<value>be/howest/kidscalcula/model/Klas.hbm.xml</value>
<value>be/howest/kidscalcula/model/Leerkracht.hbm.xml</value>
<value>be/howest/kidscalcula/model/Leerling.hbm.xml</value>
<value>be/howest/kidscalcula/model/Leerplan.hbm.xml</value>
<value>be/howest/kidscalcula/model/LeerplanOefenreeks.hbm.xml
</value>
<value>be/howest/kidscalcula/model/Leerplanonderdeel.hbm.xml</value>
<value>be/howest/kidscalcula/model/Niveau.hbm.xml</value>
<value>be/howest/kidscalcula/model/Oefenreeks.hbm.xml</value>
<value>be/howest/kidscalcula/model/Overgangsregel.hbm.xml</value>
<value>be/howest/kidscalcula/model/Rapport.hbm.xml</value>
<value>be/howest/kidscalcula/model/RapportLeerplanonderdeel.hbm.xml
</value>
<value>be/howest/kidscalcula/model/Schooljaar.hbm.xml</value>
<value>be/howest/kidscalcula/model/Subonderdeel.hbm.xml</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
<prop key="hibernate.connection.pool_size">3</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.format_sql">true</prop>
<prop key="hibernate.use_sql_comments">true</prop>
<prop key="hibernate.cache.use_second_level_cache">false</prop>
</props>
</property>
</bean>
<!-- Configure the multipart resolver -->
<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
<!-- one of the properties available; the maximum file size in bytes -->
<property name="maxUploadSize" value="500000" />
</bean>
<!--
Transaction manager for a single Hibernate SessionFactory (alternative
to JTA)
-->
<bean id="transactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>
</bean>
<tx:annotation-driven />
Does this error have anything to do with the fact that Propagation is standard Required?
Mark the method as transactional and read only to ensure the transaction does not modify any data:
#Transactional(readOnly=true)
This is an useful optimization when working with Hibernate. To read more on the implications of this annotation, here is a great post: Read-Only transactions with Spring and Hibernate
As the message clearly says, no session is bound to the thread and the configuration you have specified does NOT allow a "non-transaction" session to be created. I will try to explain each these of scenarios.
When Spring's transaction is enabled in your configuration(as you have done), Spring will wrap the SessionFactory object with a proxy that prevents creation of new sessions, if not already present, when SessionFactory.getCurrentSession is called. The proxy will only get the current session that is bound to the thread local and no ad-hoc session(non-transactional) creation is allowed by your code. This is how your configuration is preventing non-trasactional session creation.
When you annotate a method/class with #Transactional, Spring's TransactionInterceptor will create a session and bind it to the current thread when the method is called so that it is available later. Spring's OpenSessionInViewFilter, if enabled, will also bind a session to the current thread. Since you aren't doing any of these, no thread bound session is found.
What you should do is annotate your class with #Transactional(readOnly = True) and then annotate your create/update/delete methods with #Transactional(readOnly = False). It is important that you have a read-only transaction when you are reading data. This assures you that nobody can commit data during that call.
It is possible to start a session outside of a transaction even when using Spring transaction management. Call sessionFactory.openSession() to get hold of a new session. This session is local in that it is not bound to a thread and so won't be returned when you call sessionFactory.getCurrentSession(). You'll have to manage it and make sure it's properly closed at the the end of your session or if an error occurs.
You can not access the data without an (hibernate) session.
One way to provide such a session is a (when using spring):
org.springframework.orm.hibernate3.support.OpenSessionInViewFilter
or
org.springframework.orm.jpa.support.OpenEntityManagerInViewFilter
(this depends on the way you use your persistence provider)
The positive side effect of this fiters is, that the session is still open when the JSP Views are rendered - so you will have no lazy loading problems when accessing such a not yet loaded property while rendering.
#see http://community.jboss.org/wiki/OpenSessioninView
<bean id="projectService" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
<property name="transactionManager" ref="transactionManager"/>
<property name="target">
<bean class="com.company.project.company.services.ServiceImpl" init-method="init">
<property name="HRappsdao" ref="HRappsdao"/>
<property name="projectdao" ref="projectdao"/>
</bean>
</property>
<property name="transactionAttributes">
<props>
<prop key="store*">PROPAGATION_REQUIRED</prop>
<prop key="update*">PROPAGATION_REQUIRED</prop>
<prop key="remove*">PROPAGATION_REQUIRED</prop>
<prop key="bulkUpdate*">PROPAGATION_REQUIRED</prop>
<prop key="*">PROPAGATION_SUPPORTS,readOnly</prop>
</props>
</property>
</bean>
i have 2 datasource HRappsdao and projectdao, both are using different sessionFactory. in this case, my transactionmanager should be using which sessionfactory? (hrappsdao or projectdao) ?
editted
<bean id="transactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" > //my HRappsdao using same
<ref local="sessionFactory"/>
</property>
</bean>
Actually, you're not showing the configuration of your transaction manager so I'm not really sure of what your are currently using but, quoting the documentation:
JTA (usually through JtaTransactionManager) is necessary for accessing multiple transactional resources within the same transaction.
With Spring 2.5, consider using the "new" <tx:jta-transaction-manager/> configuration element for automatic detection of the underlying JTA-based transaction platform (works with most app servers). See the chapter 9.8. Application server-specific integration for more details on this.
If you are using an older version of Spring, you'll need to configure your JtaTransactionManager manually. This will require some knowledge of your application server as the JNDI location of the JTA TransactionManager is specific to each J2EE server.
Please provide more details (like the version of Spring and the application server you are using if you need more guidance).
UPDATE: As I said, when using multiple datasources, you need to use the JtaTransactionManager and not the HibernateTransactionManager (see the javadoc). If you are using Spring 2.5, update your Spring configuration as below:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">
<tx:jta-transaction-manager />
<!--
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory">
//my HRappsdao using same
<ref local="sessionFactory" />
</property>
</bean>
-->
...
</beans>
Note that you'll need something like JOTM with Tomcat or Jetty. You should maybe consider moving to a J2EE app server like JBoss or Glassfish.