2014-12-05 11 views
0

我有兩個單獨的oracle模式,我從中彙集信息並進行更新。不知何故,當我有兩個hibernate.dialect指向相同的方言,它給我同時取多個包錯誤。如果我將其中一個更改回org.hibernate.dialect.MySQLDialect,那麼錯誤會消失並編譯,但表不會生成。 休眠的另一個問題。而我的dataSource是MYSQL,我能夠生成所需的所有表,但是當我將dataSource切換到oracle時,它只會生成三個表。休眠使用兩個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; 

回答

0

將你的問題FACI ng很好的解釋了這個偉大的博客http://blog.eyallupu.com/2010/06/hibernate-exception-simultaneously.html它完美地解釋了查詢的例子,爲什麼你不能有多個袋子,並提出解決方案

你有兩個急切提取的集合,休眠由於映射組合解釋作爲袋。一個是從你的問題

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

發佈的代碼可見你有三個可能的解決方案:

  • 有你的收藏延遲加載
  • 從列表中移動的類型設置,如果你的業務邏輯允許它
  • 用@IndexColumn註釋你的收藏
相關問題