如何告诉 Hibernate 使用代理?

How to tell Hibernate to use a proxy?

目前使用 Hibernate 进行对象持久化,使用 Snowflake 作为我的数据库。 Hibernate 在尝试连接并提交到数据库时挂起。这是因为我的公司要求我们通过 proxy.

进行连接

我阅读了文档 here。该文档没有定义 Hibernate 如何通过代理进行连接……是否受支持? Hibernate 如何连接到代理上的对象,甚至可能吗?

我的 Hibernate 配置文件:

<?xml version="1.0" encoding="UTF-8"?>
<!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 name="MySessionFactory">
        <property name="hibernate.connection.driver_class">net.snowflake.client.jdbc.SnowflakeDriver</property>
        <property name="hibernate.connection.password">****</property>
        <property name="hibernate.connection.url">jdbc:snowflake://made.up.location.snowflakecomputing.com</property>
        <property name="hibernate.connection.username">myUsername</property>
        <property name="hibernate.default_schema">mySchema</property>
        <property name="hibernate.dialect">org.hibernate.dialect.DerbyDialect</property>
        <property name="show_sql">true</property>
        <property name="hibernate.c3p0.timeout">100</property>

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

我希望我们可以用类似的方式定义属性:

Properties properties = new Properties();

        properties.put("user", "myUser");
        properties.put("password", "myPassword");
        properties.put("warehouse", "warehouseName");
        properties.put("db", "databaseName");
        properties.put("schema", "mySchema");
        properties.put("role", "myRole");
        properties.put("proxyHost", "proxy.myServer.com");
        properties.put("proxyPort", "80");
        properties.put("useProxy", "true");

关于如何使这项工作有任何想法吗?

这里有一个很好的link连接Hibernate和Snowflake。 https://www.cdata.com/kb/tech/snowflake-jdbc-hibernate.rst

我通过以下方式将所有参数放入连接字符串来解决这个问题:

<property name="hibernate.connection.url">jdbc:snowflake://myCompany.us-west-3.snowflakecomputing.com/?user=username&amp;password=password&amp;warehouse=WH_Name&amp;db=DB_Name&amp;schema=SCHEMA&amp;role=MYROLE&amp;proxyHost=proxy.com&amp;proxyPort=50&amp;useProxy=true</property>

这绕过了 Snowflake 的任何困难配置设置,我现在可以完美连接了。