[英]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
&useUnicode=yes&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.