spring mvc - Hibernate using two oracle database, Error: cannot simultaneously fetch multiple bags -
i have 2 separate oracle schema pool information , update. somehow when have 2 hibernate.dialect pointing same dialect, give me simultaneously fetch multiple bags error. if change 1 of org.hibernate.dialect.mysqldialect, error disappear , compile table did not generate. question hibernate. while datasource mysql, able generate of table need, when switch datasource oracle, generate 3 table.
below persistent.xml
<!-- hibernate sessionfactory --> <bean id="sessionfactory" class="org.springframework.orm.hibernate3.annotation.annotationsessionfactorybean" p:datasource-ref="datasource"> <property name="packagestoscan" value="edu.byuh.checklist.domain" /> <property name="hibernateproperties"> <value> hibernate.dialect=org.hibernate.dialect.oracle10gdialect hibernate.transaction.factory_class=org.hibernate.transaction.jdbctransactionfactory autoreconnect=true hibernate.show_sql=true hibernate.hbm2ddl.auto=update hibernate.default_schema=checklist hibernate.flushmode=never </value> </property> </bean> <bean id="orasessionfactory" class="org.springframework.orm.hibernate3.annotation.annotationsessionfactorybean" p:datasource-ref="oradatasource"> <!-- <property name="annotatedclasses"> <list> <value>edu.byuh.checklist.oradomain.psuserdetails</value> <value>edu.byuh.checklist.oradomain.housingassignment</value> <value>edu.byuh.checklist.oradomain.housingfee</value> </list> </property> --> <property name="packagestoscan" value="edu.byuh.checklist.oradomain" /> <property name="hibernateproperties"> <value> hibernate.dialect=org.hibernate.dialect.oracle10gdialect <!-- hibernate.show_sql=true --> hibernate.transaction.factory_class=org.hibernate.transaction.jdbctransactionfactory autoreconnect=true hibernate.default_schema=sysadm <!-- maxconnectionage = 4 * 60 * 60 maxidletimeexcessconnections = 30 * 60 --> hibernate.jdbc.batch_size=${hibernate.jdbc.batch_size} hibernate.c3p0.max_size=${hibernate.c3p0.max_size} hibernate.c3p0.min_size=${hibernate.c3p0.min_size} hibernate.c3p0.timeout=${hibernate.c3p0.timeout} hibernate.c3p0.max_statements=${hibernate.c3p0.max_statements} hibernate.c3p0.idle_test_period=${hibernate.c3p0.idle_test_period} </value> </property> </bean> <!-- <beans:prop key="hibernate.transaction.factory_class"> org.hibernate.transaction.jdbctransactionfactory </beans:prop> --> <!-- <beans:property name="hibernateproperties"> <beans:props> <beans:prop key="hibernate.dialect"> org.hibernate.dialect.oracle10gdialect</beans:prop> <beans:prop key="hibernate.show_sql">true</beans:prop> <beans:prop key="hibernate.transaction.factory_class"> org.hibernate.transaction.jdbctransactionfactory </beans:prop> prop key="hibernate.hbm2ddl.auto">update</prop <beans:prop key="hibernate.default_schema">sysadm</beans:prop> </beans:props> </beans:property> </beans:bean> --> <!-- read in daos hibernate package --> <context:component-scan base-package="edu.byuh.checklist.dao.hibernate" /> <!-- transaction config --> <bean id="transactionmanager" class="org.springframework.orm.hibernate3.hibernatetransactionmanager" p:sessionfactory-ref="sessionfactory" /> <bean id="oratransactionmanager" class="org.springframework.orm.hibernate3.hibernatetransactionmanager" p:sessionfactory-ref="orasessionfactory" /> <!-- <aop:config proxy-target-class="true"/> --> <tx:annotation-driven transaction-manager="transactionmanager" />
below of domain class
@suppresswarnings("serial") @entity @table(name = "checklistitem") @inheritance(strategy = inheritancetype.single_table) @discriminatorcolumn(name="itemtype", discriminatortype=discriminatortype.string) public abstract class checklistitem implements domainobject, comparable<checklistitem>{ //@sequencegenerator(name = "mysequence", sequencename = "my_seq", allocationsize=1) @sequencegenerator(name = "hibernate_sequence", sequencename = "checklistitem", allocationsize=1) @id @generatedvalue(strategy = generationtype.table) private integer id; private string title; private string subtitle; private boolean published; @column(length=2560) private string contenttxt; //list of student attributes @elementcollection(fetch = fetchtype.eager) @enumerated(enumtype.string) private list<studentattribute> appliesto;
another domain class
@entity @primarykeyjoincolumn(name = "fk_id", referencedcolumnname = "id") public class infoitemuser extends checklistitemuser implements domainobject { private integer tries;
the problem you're facing explained in great blog http://blog.eyallupu.com/2010/06/hibernate-exception-simultaneously.html explains query example, why can't have multiple bags, , proposes solution
you have 2 eagerly fetched collections hibernate due mapping combination interprets bag. 1 visible code posted in question
@elementcollection(fetch = fetchtype.eager) @enumerated(enumtype.string) private list<studentattribute> appliesto;
you have 3 possible solutions:
- have collections lazily loaded
- move type list set if business logic allows it
- annotate collections @indexcolumn
Comments
Post a Comment