如何在heroku上配置hibernate ORM? [英] How do I configure hibernate ORM on heroku?
问题描述
这是我在hibernate.cfg.xml中的
Here is what I have in 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>
此外,我将动态覆盖某些属性...
Also, I am overriding some properties dynamically...
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", "***");
但是,当我运行它,我得到这个错误...
But, when I run it, I get this error...
ERROR: No suitable driver found for postgres://*******:*********@ec2-23-21-85-197.compute-1.amazonaws.com:5432/d9i5vp******o7te
如何配置我的属性,让heroku找到postgres驱动程序?
How do I configure my properties so that heroku finds the postgres driver?
(我是新的hibernate和heroku,所以任何帮助非常感谢:)
(I am new to hibernate and heroku, so any help is greatly appreciated :)
推荐答案
来自Heroku Postgres的URL格式不是JDBC格式。它是一个多语言格式,所以所有平台都可以使用它。所以你需要将URL转换为JDBC格式。在Heroku开发中心有一个很好的例子:
https://devcenter.heroku.com/articles/connecting-to-relational-databases-on-heroku-with-java# use-the-in-plain-jdbc
The URL format that comes from Heroku Postgres is not the JDBC format. It is a polyglot format so that all platforms can use it. So you need to transform the URL to the JDBC format. There is a good example of how to do that on the Heroku Dev Center:
https://devcenter.heroku.com/articles/connecting-to-relational-databases-on-heroku-with-java#using-the-in-plain-jdbc
这篇关于如何在heroku上配置hibernate ORM?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!