我有一个空白的Spring MVC项目,我已经使用Maven安装了Hibernate和PostgreSQL驱动程序.

关于如何将PostgreSQL与Hibernate连接的完整教程,我已经很缺乏了.

有人帮忙吗?

推荐答案

这是冬眠.cfg.xml,它将帮助您完成posgresql的基本hibernate配置.

<!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>
        <property name="hibernate.dialect">org.hibernate.dialect.PostgreSQLDialect</property>
        <property name="hibernate.connection.driver_class">org.postgresql.Driver</property>
        <property name="hibernate.connection.username">postgres</property>
        <property name="hibernate.connection.password">password</property>
        <property name="hibernate.connection.url">jdbc:postgresql://localhost:5432/hibernatedb</property>



        <property name="connection_pool_size">1</property>

        <property name="hbm2ddl.auto">create</property>

        <property name="show_sql">true</property>



       <mapping class="org.javabrains.sanjaya.dto.UserDetails"/>

    </session-factory>
</hibernate-configuration>

Postgresql相关问答推荐

读取扩展坞合成中的UDP:IO/超时

有没有一种方法可以在参数中添加密码,并在批处理文件中需要时自动获取密码?

我可以使用 SQLAlchemy 映射数据类创建 Postgres `GENERATED ALWAYS AS` 列吗?

空表上的 Postgres 意外行为

Supabase 数据库大小问题

订阅标签保存在哪个表中?

如何为基于复合类型的 Postgres DOMAIN 定义 CHECK 约束

postgresql查询中的正则表达式不区分大小写

postgreSQL 中对 utf-8 的 LC_COLLATE 和 LC_CTYPE 支持

在 to_tsquery 中转义特殊字符

升级到 OSX Mavericks 后修复 postgresql

PostgreSQL如何连接间隔值'2天'

Postgres 默认按 id 排序 - worldship

在 Windows 10 中执行时,Docker 容器关闭并给出data directory has wrong ownership错误

错误:ERROR: table name specified more than once

如何为 Postgres psql 设置时区?

Postgres Hstore 与 Redis - 性能方面

在布尔字段上添加索引

错误:permission denied for language c

如何在 PostgreSQL 中生成一系列重复数字?