【问题标题】:Hibernate using two oracle database, Error: cannot simultaneously fetch multiple bagsHibernate 使用两个 oracle 数据库,错误:无法同时获取多个包
【发布时间】:2015-02-04 02:31:28
【问题描述】:

我有两个独立的 oracle 架构,我从中汇集信息并进行更新。不知何故,当我有两个 hibernate.dialect 指向同一个方言时,它给了我同时获取多个包错误。如果我将其中之一改回 org.hibernate.dialect.MySQLDialect,错误消失并编译,但表没有生成。 另一个关于休眠的问题。虽然我的数据源是 MYSQL,但我能够生成我需要的所有表,但是当我将数据源切换到 oracle 时,它​​只生成三个表。

下面是我的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 from the 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" />

下面是我的一些领域类

@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;

另一个域类

@Entity
@PrimaryKeyJoinColumn(name = "Fk_id", referencedColumnName = "id")
public class InfoItemUser extends CheckListItemUser implements DomainObject {

private Integer tries;

【问题讨论】:

    标签: hibernate spring-mvc oracle11g


    【解决方案1】:

    这个很棒的博客http://blog.eyallupu.com/2010/06/hibernate-exception-simultaneously.html很好地解释了您面临的问题,它通过一个查询示例完美地解释了为什么您不能拥有多个包,并提出了解决方案

    您有两个急切获取的集合,由于映射组合解释为包而休眠。从您发布的代码中可以看到一个

    @ElementCollection(fetch = FetchType.EAGER)
    @Enumerated(EnumType.STRING)
    private List<StudentAttribute> appliesTo;
    

    您有三种可能的解决方案:

    • 延迟加载您的收藏集
    • 如果您的业务逻辑允许,将类型从 List 移至 Set
    • 使用 @IndexColumn 注释您的集合

    【讨论】:

      猜你喜欢
      • 2011-11-02
      • 1970-01-01
      • 2013-05-03
      • 2023-04-04
      • 2011-05-19
      • 2021-11-20
      • 2020-05-17
      • 2019-03-18
      • 1970-01-01
      相关资源
      最近更新 更多