-1

我正在尝试使用不同的表连接到另一个数据库(SQL 服务器)。我设法连接,但它在另一个数据库中搜索同一个表。

如何说应该在哪些数据库表中,哪些不应该?

实体 :

@Entity(name = "ripError")
@Table(name = "rip_error")
public class RipError {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Integer id;

    @Column(name = "deleted")
    private char deleted;
    @Column(name = "error_code")
    private String errorCode;
    @Column(name = "error_desc")
    private String errorDesc;
}

弹簧数据.xml

 <context:property-placeholder properties-ref="deployProperties" />

    <tx:annotation-driven transaction-manager="transactionManager"  />  

    <!-- Activate Spring Data JPA repository support -->
    <jpa:repositories base-package="com.worldone.repository" entity-manager-factory-ref="entityManagerFactory" transaction-manager-ref="transactionManager" />
    <jpa:repositories base-package="com.worldone.repositoryMetal" entity-manager-factory-ref="entityManagerFactoryMetal" transaction-manager-ref="transactionManagerMetal" />

    <!-- Declare a datasource that has pooling capabilities-->   
    <bean id="jpaDataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"
        destroy-method="close" 
        p:driverClass="${app.jdbc.driverClassName}"
        p:jdbcUrl="${app.jdbc.url}"
        p:user="${app.jdbc.username}"
        p:password="${app.jdbc.password}"
        p:acquireIncrement="5"
        p:idleConnectionTestPeriod="60"
        p:maxPoolSize="100"
        p:maxStatements="50"
        p:minPoolSize="10" 

        />

    <bean id="jpaDataSourceMetal" class="com.mchange.v2.c3p0.ComboPooledDataSource"
        destroy-method="close"
        p:driverClass="${app2.jdbc.driverClassName}"
        p:jdbcUrl="${app2.jdbc.url}"
        p:user="${app2.jdbc.username}"
        p:password="${app2.jdbc.password}"
        p:acquireIncrement="5"
        p:idleConnectionTestPeriod="60"
        p:maxPoolSize="100"
        p:maxStatements="50"
        p:minPoolSize="10" 

        />


    <!-- Declare a JPA entityManagerFactory -->
    <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean" 
        p:persistenceXmlLocation="classpath*:META-INF/persistence.xml"
        p:persistenceUnitName="hibernatePersistenceUnit"

        p:dataSource-ref="jpaDataSource"
        p:jpaVendorAdapter-ref="hibernateVendor"/>

    <!-- Declare a JPA entityManagerFactory -->
    <bean id="entityManagerFactoryMetal" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean" 
        p:persistenceXmlLocation="classpath*:META-INF/persistence.xml"
        p:persistenceUnitName="hibernatePersistenceUnitMetal"
        p:dataSource-ref="jpaDataSourceMetal"
        p:jpaVendorAdapter-ref="hibernateVendorMetal"/>



    <!-- Specify our ORM vendor -->
    <bean id="hibernateVendor" class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"
                p:showSql="false"/>
    <!-- Specify our ORM vendor -->
    <bean id="hibernateVendorMetal" class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"
                p:showSql="false"/>


    <!-- Declare a transaction manager-->
    <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager" 
        p:entityManagerFactory-ref="entityManagerFactory"

        />

    <!-- Declare a transaction manager-->
    <bean id="transactionManagerMetal" class="org.springframework.orm.jpa.JpaTransactionManager" 
        p:entityManagerFactory-ref="entityManagerFactoryMetal"/>

这是错误:

Caused by: javax.persistence.PersistenceException: [PersistenceUnit: hibernatePersistenceUnitMetal] Unable to build EntityManagerFactory
Caused by: org.hibernate.HibernateException: Missing table: rip_error
4

2 回答 2

1

您可能希望拥有不同的持久性单元。每个都有自己的类集合和自己的数据源。

请参阅:是否可以为多个数据源配置 persistence.xml?

于 2013-02-25T15:01:38.873 回答
0

检查是否有助于解决您的问题

于 2013-02-25T14:53:01.220 回答