Hibernate使用两个oracle数据库,错误:无法同时获取多个包

时间:2014-12-05 20:20:43

标签: hibernate spring-mvc oracle11g

我有两个独立的oracle架构,我汇集信息并更新。不知怎的,当我有两个hibernate.dialect指向同一个方言时,它同时给我提取多个包错误。如果我将其中一个更改回org.hibernate.dialect.MySQLDialect,则错误消失并编译,但表未生成。 休眠的另一个问题。虽然我的dataSource是MYSQL,但我能够生成我需要的所有表,但是当我将dataSource切换到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;

1 个答案:

答案 0 :(得分:0)

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

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

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

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

  • 让你的藏品懒洋洋地加载
  • 如果您的业务逻辑允许,则将类型从列表移动到设置
  • 使用@IndexColumn
  • 注释您的馆藏