0

好的,我对此很陌生。我想做的是说“这些类在这里(数据库a)和这些类在那里(数据库b)持久化”。我我应该在不同的持久性单元组下明确定义类,这些组还可以包含带有驱动程序信息的属性集合。

<persistence-unit name="nytdModel" transaction-type="RESOURCE_LOCAL">
  <provider>org.hibernate.ejb.HibernatePersistence</provider>
  <class>gov.vermont.dcf.nytd.model.AbstractElementImpl</class>
  ...
  <exclude-unlisted-classes>true</exclude-unlisted-classes>
  <properties>
    <property name="hibernate.connection.driver_class" value="net.sourceforge.jtds.jdbc.Driver"/>
    <property name="hibernate.connection.url" value="jdbc:jtds:sqlserver://localhost;..."/>
    <property name="hibernate.connection.username" value="..."/>
    <property name="hibernate.connection.password" value="..."/>
  </properties>
</persistence-unit>

然后在我的道课程中,我应该只提供上下文:

@Repository
public class AFCARSJpaDao
{
    @PersistenceContext(unitName = "nytdModel")
    private EntityManager entityManger;
}

但是,我遇到了一个No unique bean of type [javax.persistence.EntityManagerFactory] is defined: expected single bean but found 2错误。我究竟做错了什么?

我正在使用 Spring 3.0.4

4

1 回答 1

2

看起来你试图在某个地方注入一个EntityManagerFactorywith @Autowired

始终使用@PersistenceContextto injectionEntityManager@PersistenceUnitto injection EntityManagerFactory,它们应该正确处理多个持久性单元的情况(如果您unitName在它们上指定属性)。

于 2011-05-23T19:09:56.303 回答