【问题标题】:Hibernate Postgresql Schema休眠 Postgresql 模式
【发布时间】:2013-04-28 02:40:04
【问题描述】:

我正在使用休眠 POJO 类和映射访问 Postgresql 数据库。现在我添加了一个名为“OCS”的新模式,但无法生成类和映射。这是我的 hibernate.cfg.xml

 <property name='hibernate.connection.driver_class'>org.postgresql.Driver</property>
  <property name='hibernate.connection.url'>jdbc:postgresql://test/test_mytest</property>

  <property name='hibernate.connection.username'>username</property>
  <property name='hibernate.connection.password'>password</property>
  <property name='hibernate.connection.pool_size'>10</property>
  <property name='show_sql'>true</property>
  <property name='dialect'>org.hibernate.dialect.PostgreSQLDialect</property>

【问题讨论】:

  • 您可以更改 Postgres 用户以将 ocs 设为默认架构。

标签: hibernate postgresql schema


【解决方案1】:

有几种方法可以影响 PostgreSQL 的默认搜索路径:

  1. 您可以在 postgresql.conf 中全局设置它(添加类似search_path=ocs 的内容并重新启动)。这是一个生硬的工具,我不推荐它。

  2. 您可以在数据库上设置它。 ALTER DATABASE mydb set search_path=ocs 这不是一个糟糕的选择。它将它限制在数据库中,但将其设为所有连接到数据库的应用程序的默认值,因此可能仍然过于生硬。

  3. 您可以在用户上设置它。 ALTER USER myuser SET search_path=ocs 如果用户连接到多个数据库并且许多数据库没有此架构,则此方法效果不佳.....

  4. 您可以在会话中设置它。连接后,只需发送以下 SQL:SET search_path=ocs

【讨论】:

    猜你喜欢
    • 2013-06-30
    • 1970-01-01
    • 2016-09-26
    • 2014-10-09
    • 1970-01-01
    • 2014-12-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多