Обсуждение: Configuring Hibernate for PostgreSQL Access Over Unix Socket WithJDBC
Hello,
I hope it is appropriate to send this question to this address. If not, kindly redirect me.
I am trying to configure Hibernate to use a Unix socket connection to my local PostgreSQL installation. I have referred to this doc:
https://jdbc.postgresql.org/documentation/head/connect.html#connection-parameters
and have been trying entries in hibernate.cfg.xml along these lines:
<property name="hibernate.connection.url">jdbc:postgresql:kokodoko?socketFactory=org.newsclub.net.unix.socketfactory.PostgresqlAFUNIXSocketFactory&socketFactoryArg=/var/run/postgresql/.s.PGSQL.5432</property>
The XML validator in Eclipse is flagging this error:
The reference to entity "socketFactoryArg" must end with the ';' delimiter.
(Of course I have tried many variations such as inserting semicolons in various places, quoting the argument, using square brackets and so on.)
If I ignore the error and try to use config file I get this error:
{
"error": {
"errors": [
{
"domain": "global",
"reason": "backendError",
"message": "org.hibernate.internal.util.config.ConfigurationException: Unable to perform unmarshalling at line number 0 and column 0 in RESOURCE hibernate.cfg.xml. Message: null"
}
],
"code": 503,
"message": "org.hibernate.internal.util.config.ConfigurationException: Unable to perform unmarshalling at line number 0 and column 0 in RESOURCE hibernate.cfg.xml. Message: null"
}
}
which I take to mean that the config file is unusable.
Is what I am trying to do (Hibernate, JDBC, PostgreSQL, hibernate.cfg.xml, Unix socket) possible? If so, kindly give me some guidance. If not, can you suggest a different approach that uses a Unix socket?
I am posting a similar request on the Hibernate forum.
Thanks very much.
-Dan
On 8.12.2019 14:13, Dan wrote:
<property name="hibernate.connection.url">jdbc:postgresql:kokodoko?socketFactory=org.newsclub.net.unix.socketfactory.PostgresqlAFUNIXSocketFactory&socketFactoryArg=/var/run/postgresql/.s.PGSQL.5432</property>
Is the issue the unescaped ampersand? (the "&")Replace any raw & in the URL value with & and see if that works. I think this is just an XML parsing issue unrelated to the driver itself.
Also the documentation of `junixsockets` mentions three ways to provide the configuration of the JDBC connection for PostgreSQL. https://kohlschutter.github.io/junixsocket/dependency.html
It states mandatory use of `localhost` in the connection string for variant 1 and 2. IMO You are using variant 1.
-- Поздрави, | Best regards, Радослав Петров | Radoslav Petrov
Hi Sehrope,
Thank you for the reply and suggestion. The unescaped ampersand was causing the problem. I am now able to connect.
-Dan
Is the issue the unescaped ampersand? (the "&")Replace any raw & in the URL value with & and see if that works. I think this is just an XML parsing issue unrelated to the driver itself.
Hi Radoslav,
Thanks very much for getting back to me.
Here is the config line that is now working for me:
<property name="hibernate.connection.url">jdbc:postgresql:kokodoko?socketFactory=org.newsclub.net.unix.socketfactory.PostgresqlAFUNIXSocketFactory&socketFactoryArg=/var/run/postgresql/.s.PGSQL.5432</property>
-Dan
On 8.12.2019 14:13, Dan wrote:<property name="hibernate.connection.url">jdbc:postgresql:kokodoko?socketFactory=org.newsclub.net.unix.socketfactory.PostgresqlAFUNIXSocketFactory&socketFactoryArg=/var/run/postgresql/.s.PGSQL.5432</property>On 8.12.2019 15:27, Sehrope Sarkuni wrote:Is the issue the unescaped ampersand? (the "&")Replace any raw & in the URL value with & and see if that works. I think this is just an XML parsing issue unrelated to the driver itself.
Also the documentation of `junixsockets` mentions three ways to provide the configuration of the JDBC connection for PostgreSQL. https://kohlschutter.github.io/junixsocket/dependency.html
It states mandatory use of `localhost` in the connection string for variant 1 and 2. IMO You are using variant 1.-- Поздрави, | Best regards, Радослав Петров | Radoslav Petrov