简体   繁体   English

引起:org.postgresql.util.PSQLException:尝试自动创建数据库时数据库不存在

[英]Caused by: org.postgresql.util.PSQLException: database doesn't exist when trying to auto-create database

I have this hibernate.cfg.xml :我有这个hibernate.cfg.xml

<!DOCTYPE hibernate-configuration PUBLIC
        "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
        "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
    <session-factory>
        <!-- Database connection settings -->
        <property name="connection.driver_class">org.postgresql.Driver</property>

        <property name="connection.url">
            jdbc:postgresql://localhost/DatabaseName?createDatabaseIfNotExist=true
                &amp;useUnicode=yes&amp;characterEncoding=UTF-8
        </property>

        <property name="connection.username">postgres</property>
        <property name="connection.password">password</property>
        <!-- JDBC connection pool (use the built-in) -->
        <property name="connection.pool_size">5</property>
        <!-- SQL dialect -->
        <property name="dialect">org.hibernate.dialect.PostgreSQL9Dialect</property>
        <!-- Disable the second-level cache -->
        <property name="cache.provider_class">org.hibernate.cache.internal.NoCachingRegionFactory</property>
        <!-- Echo all executed SQL to stdout -->
        <property name="show_sql">true</property>
        <!-- Drop and re-create the database schema on startup -->
        <property name="hbm2ddl.auto">update</property>
        <mapping class="com.main.User"/>
    </session-factory>
</hibernate-configuration>

which is supposed to create both tables (for the User entity and the database DatabaseName ).它应该创建两个表(用于User实体和数据库DatabaseName )。 However, it doesn't create a database and fails with an error on this line:但是,它不会创建数据库并且失败并在此行上显示错误:

sessionFactory = configuration.buildSessionFactory();

What can I do to make it autocreate database titled DatabaseName ?我该怎么做才能使它自动创建名为DatabaseName

To create database you have to create is manually you can use IDEs for that or cmd to create your DB要创建您必须手动创建的数据库,您可以使用 IDE 或 cmd 来创建您的数据库

And To create Tables you can use create in place of update并且要创建表,您可以使用 create 代替 update

 <!-- Drop and re-create the database schema on startup -->
    <property name="hbm2ddl.auto">create</property>

It will create a schema and then you will use an update for the next startup if you don`t want to recreate your tables它将创建一个架构,然后如果您不想重新创建表,您将在下次启动时使用更新

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 org.postgresql.util.PSQLException:致命:数据库“ postgres&gt;”不存在 - org.postgresql.util.PSQLException: FATAL: database “postgres>” does not exist org.postgresql.util.PSQLException:致命:数据库“&lt;<database_name> &gt;” 不存在,在 AWS java lambda</database_name> - org.postgresql.util.PSQLException: FATAL: database “<<database_name>>” does not exist, in the AWS java lambda org.postgresql.util.PSQLException:致命:数据库“pma-springbootdb” - org.postgresql.util.PSQLException: FATAL: database “pma-springbootdb” 由以下原因引起:org.postgresql.util.PSQLException:错误:类型“枚举”不存在 - Caused by: org.postgresql.util.PSQLException: ERROR: type “enum” does not exist 引起:org.postgresql.util.PSQLException:错误:运算符不存在:文本= integer - Caused by: org.postgresql.util.PSQLException: ERROR: operator does not exist: text = integer 如何解决“Caused by: org.postgresql.util.PSQLException: ERROR: relation “employee” does not exist Position: 13”错误? - How to resolve "Caused by: org.postgresql.util.PSQLException: ERROR: relation "employee" does not exist Position: 13" error? 引起:org.postgresql.util.PSQLException:错误:“:”处或附近的语法错误 - Caused by: org.postgresql.util.PSQLException: ERROR: syntax error at or near ":" org.postgresql.util.PSQLException:错误:关系“序列”不存在 - org.postgresql.util.PSQLException: ERROR: relation “sequence” does not exist org.postgresql.util.PSQLException:错误:关系“产品”不存在 - org.postgresql.util.PSQLException: ERROR: relation "products" does not exist 引起:org.postgresql.util.PSQLException:错误:列 performanc3_.app_user_internal_user_id 不存在 - Caused by: org.postgresql.util.PSQLException: ERROR: column performanc3_.app_user_internal_user_id does not exist
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM