如何在heroku上配置hibernate ORM?

Mar*_*nov 6 configuration hibernate heroku

这是我在hibernate.cfg.xml中的内容

<hibernate-configuration>
    <session-factory>
        <property name="hibernate.hbm2ddl.auto">update</property>
        <property name="hibernate.ejb.naming_strategy">org.hibernate.cfg.ImprovedNamingStrategy</property>
        <property name="hibernate.connection.charSet">UTF-8</property> 
        <property name="hibernate.connection.driver_class">org.postgresql.Driver</property>
        <property name="connection.driver_class">org.postgresql.Driver</property>
        <property name="hibernate.dialect">org.hibernate.dialect.PostgreSQLDialect</property>
        <property name="connection.pool_size">1</property>
        <property name="show_sql">true</property>
        <property name="hibernate.use_outer_join">true</property>
        <property name="current_session_context_class">thread</property>
    </session-factory>
</hibernate-configuration>
Run Code Online (Sandbox Code Playgroud)

另外,我动态地覆盖了一些属性......

 Configuration config = new Configuration().configure("path_to_hibernate.cfg.xml");
 config.setProperty("hibernate.connection.url", System.getenv("HEROKU_POSTGRESQL_MYCOLOR_URL"));
 config.setProperty("hibernate.connection.username", "***");
 config.setProperty("hibernate.connection.password", "***");
Run Code Online (Sandbox Code Playgroud)

但是,当我运行它时,我收到此错误...

ERROR: No suitable driver found for postgres://*******:*********@ec2-23-21-85-197.compute-1.amazonaws.com:5432/d9i5vp******o7te
Run Code Online (Sandbox Code Playgroud)

如何配置我的属性以便heroku找到postgres驱动程序?

(我是hibernate和heroku的新手,所以任何帮助都非常感谢:)

Jam*_*ard 0

来自 Heroku Postgres 的 URL 格式不是 JDBC 格式。它是一种多语言格式,因此所有平台都可以使用它。所以需要将URL转换为JDBC格式。Heroku 开发中心有一个很好的示例说明如何执行此操作:
https://devcenter.heroku.com/articles/connecting-to-relational-databases-on-heroku-with-java#using-the-in-普通 jdbc