Hibernate实体管理器,以不同模式查找表

Pra*_*ant 6 java hibernate jpa

我在Java Web项目中使用hiberante-entity Manager实现jpa持久性。我在persistence.xml中设置了以下属性。

<property name="hibernate.hbm2ddl.auto" value="update"/>

我为每个用户都有一个架构。例如,我有一个用于user1的模式,一个用于user2的模式。如果表“ ABC”存在于user1架构中,但没有出现在user2架构中,并且我部署了该应用程序,并且使用了user2 db凭据,则会收到消息“ user1.ABC”表,因此不会在user2中创建“ ABC”表模式。

当我尝试在persistence.xml文件中使用以下属性时,将在user2模式中创建表。

 <property name="hibernate.hbm2ddl.auto" value="create"/>   
Run Code Online (Sandbox Code Playgroud)

我的问题是,如果应用程序使用了user2 db凭据,为什么hibernate在另一个模式(即user1)中搜索?而且我不想每次启动服务器时都创建架构,因此如何避免使用值'create'。

编辑:以下是我的persistence.xml文件

    <persistence xmlns="http://java.sun.com/xml/ns/persistence" version="1.0">
    <persistence-unit name="XXXXXX" transaction-type="RESOURCE_LOCAL">
    <provider>org.hibernate.ejb.HibernatePersistence</provider>

    <class>org.axonframework.saga.repository.jpa.SagaEntry</class>
    <class>org.axonframework.saga.repository.jpa.AssociationValueEntry</class>

    <properties>
        <property name="hibernate.archive.autodetection" value="class"/>
        <property name="hibernate.hbm2ddl.auto" value="update"/> 
    </properties>
</persistence-unit>
</persistence>
Run Code Online (Sandbox Code Playgroud)

提前致谢

小智 3

我也面临着同样的问题,经过大量挖掘后,发现该错误与 Mysql Connector 有关。将 MySql Connector 6.0.5更改为5.1.28后,它对我来说工作得很好。我希望它可以帮助你。干杯