K
kdkkdkddkdkkd
Gast
Hallo!
Ich habe ein großes Problem: Ich programmiere eine Konsolenanwendung mit Spring und AOP. Derzeit versuche ich (testweise) auf eine Datenbank zuzugreifen, ein Element abzuholen und dies wieder zu speichern, um zu sehen ob das Transaktionsmanagement funkioniert. Leider bekomme ich aber folgenden Error:
[WR]Exception in thread "main" org.hibernate.HibernateException: Illegal attempt to associate a collection with two open sessions
[/WR]
Dieser Fehler tritt auf bei der UserDaoImpl.saveOrUpdate(u);
Hier meine konfiguration:
UserDaoImpl.
ApplicationContext
[XML]<?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:jee="http://www.springframework.org/schema/jee"
xmlns:aop="http://www.springframework.org/schema/aop" 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-2.5.xsd
Index of /schema/jee
http://www.springframework.org/schema/jee/spring-jee-2.5.xsd
Index of /schema/aop
http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
Index of /schema/tx
http://www.springframework.org/schema/tx/spring-tx-2.5.xsd
Index of /schema/util
http://www.springframework.org/schema/util/spring-util-2.5.xsd
">
<bean id="transactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="shopSessionFactory" />
</bean>
<bean id="localDataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="org.postgresql.Driver" />
<property name="url"
value="jdbc
ostgresql://localhost:******" />
<property name="username" value="***" />
<property name="password" value="***" />
</bean>
<bean id="shopSessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource" ref="localDataSource" />
<property name="mappingResources" ref="shopMappingResources" />
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.PostgreSQLDialect</prop>
<prop key="hibernate.format_sql">false</prop>
<prop key="hibernate.show_sql">false</prop>
</props>
</property>
</bean>
<tx:advice id="txShopAdvise" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="get**" propagation="SUPPORTS" read-only="true" />
<tx:method name="save**" propagation="REQUIRED" />
<tx:method name="delete**" propagation="REQUIRED" />
</tx:attributes>
</tx:advice>
<aop:config>
<aop
ointcut id="daoShopTransaction"
expression="execution(* dao.*Dao.*(..))" />
<aop:advisor advice-ref="txShopAdvise" pointcut-ref="daoShopTransaction" />
</aop:config>
<!-- DAO Shop -->
<bean id="userDao" class="dao.UserDaoImpl">
<property name="sessionFactory" ref="shopSessionFactory" />
</bean>
<bean id="newsletterDao" class="dao.NewsletterDaoImpl">
<property name="sessionFactory" ref="shopSessionFactory" />
</bean>
<bean id="newsletterFailedReasonTypeDao"
class="dao.NewsletterFailedReasonTypeDaoImpl">
<property name="sessionFactory" ref="shopSessionFactory" />
</bean>
<bean id="newsletterFailedReasonDao"
class="dao.NewsletterFailedReasonDaoImpl">
<property name="sessionFactory" ref="shopSessionFactory" />
</bean>
<bean id="shopMappingResources" class="java.util.ArrayList">
<constructor-arg>
<list>
.....
</list>
</constructor-arg>
</bean>
</beans>
[/XML]
Ich suche den Fehler nun schon seit 2 Tagen, schön langsam bin ich am Verzweifeln. Wäre echt toll wenn mir jemand sagen könnte, was ich falsch mache :O
Schönen Tag noch
Ich habe ein großes Problem: Ich programmiere eine Konsolenanwendung mit Spring und AOP. Derzeit versuche ich (testweise) auf eine Datenbank zuzugreifen, ein Element abzuholen und dies wieder zu speichern, um zu sehen ob das Transaktionsmanagement funkioniert. Leider bekomme ich aber folgenden Error:
[WR]Exception in thread "main" org.hibernate.HibernateException: Illegal attempt to associate a collection with two open sessions
[/WR]
Dieser Fehler tritt auf bei der UserDaoImpl.saveOrUpdate(u);
Hier meine konfiguration:
Java:
NewsletterDao ndao = (NewsletterDao) applicationContext.getBean("newsletterDao");
ndao.saveOrUpdate(ndao.getNewsletterById(0)); //Funktioniert
Newsletter nltr = ndao.getNewsletterById(0);
Mandant mandant = nltr.getMandant();
UserDao ud = (UserDao) applicationContext.getBean("userDao");
User u = ud.getUserByEmail(mandant, "email@email.email");
System.out.println(u.getAddress());
ud.saveOrUpdate(u); // HIER FEHLERMELDUNG
UserDaoImpl.
Java:
public void saveOrUpdate(User user) {
if (user.getAddress().getEmail() == null) {
user.getAddress().setEmail(user.getEmail());
}
getSession().saveOrUpdate(user);
getSession().saveOrUpdate(user.getAddress());
}
ApplicationContext
[XML]<?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:jee="http://www.springframework.org/schema/jee"
xmlns:aop="http://www.springframework.org/schema/aop" 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-2.5.xsd
Index of /schema/jee
http://www.springframework.org/schema/jee/spring-jee-2.5.xsd
Index of /schema/aop
http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
Index of /schema/tx
http://www.springframework.org/schema/tx/spring-tx-2.5.xsd
Index of /schema/util
http://www.springframework.org/schema/util/spring-util-2.5.xsd
">
<bean id="transactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="shopSessionFactory" />
</bean>
<bean id="localDataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="org.postgresql.Driver" />
<property name="url"
value="jdbc
<property name="username" value="***" />
<property name="password" value="***" />
</bean>
<bean id="shopSessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource" ref="localDataSource" />
<property name="mappingResources" ref="shopMappingResources" />
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.PostgreSQLDialect</prop>
<prop key="hibernate.format_sql">false</prop>
<prop key="hibernate.show_sql">false</prop>
</props>
</property>
</bean>
<tx:advice id="txShopAdvise" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="get**" propagation="SUPPORTS" read-only="true" />
<tx:method name="save**" propagation="REQUIRED" />
<tx:method name="delete**" propagation="REQUIRED" />
</tx:attributes>
</tx:advice>
<aop:config>
<aop
expression="execution(* dao.*Dao.*(..))" />
<aop:advisor advice-ref="txShopAdvise" pointcut-ref="daoShopTransaction" />
</aop:config>
<!-- DAO Shop -->
<bean id="userDao" class="dao.UserDaoImpl">
<property name="sessionFactory" ref="shopSessionFactory" />
</bean>
<bean id="newsletterDao" class="dao.NewsletterDaoImpl">
<property name="sessionFactory" ref="shopSessionFactory" />
</bean>
<bean id="newsletterFailedReasonTypeDao"
class="dao.NewsletterFailedReasonTypeDaoImpl">
<property name="sessionFactory" ref="shopSessionFactory" />
</bean>
<bean id="newsletterFailedReasonDao"
class="dao.NewsletterFailedReasonDaoImpl">
<property name="sessionFactory" ref="shopSessionFactory" />
</bean>
<bean id="shopMappingResources" class="java.util.ArrayList">
<constructor-arg>
<list>
.....
</list>
</constructor-arg>
</bean>
</beans>
[/XML]
Ich suche den Fehler nun schon seit 2 Tagen, schön langsam bin ich am Verzweifeln. Wäre echt toll wenn mir jemand sagen könnte, was ich falsch mache :O
Schönen Tag noch