5

I recently started to learn Hibernate technology and have to get data from a database using Hibernate. The problem is that I can connect to the database only via an SSH tunnel. Are there any properties which I can use in the hibernate.cfg.xml file to solve this problem? Or may be you can suggest another way which will be understandable to a newbie.

2
  • Can you build a simple JDBC connection through this SSH tunnel? What DB do you use? Commented Sep 7, 2012 at 11:33
  • @Tichodroma , previosly I tried to connect to this MySQL database only manually, using MySQL clients... Commented Sep 7, 2012 at 11:44

1 Answer 1

5

Maybe using Jsch. Some examples could give you a way to go.

Another way could be implementing your own SSH SocketFactory, maybe with http proxy handler and port forwarding stuff. A starting point could be:

SSHSocketFactory fact = new SSHSocketFactory(sshHost, sshPort, new SSHPasswordAuthenticator(sshUser, sshPassword));

sock = fact.createSocket(host, port);

And you could link your implementation with the following parameter inside your hibernate.cfg.xml file:

hibernate.connection.socketFactory=com.mysql.jdbc.NamedPipeSocketFactory

Or maybe like the way they do here or here (the latter is the better way to go).

Good ssh stuff!

Sign up to request clarification or add additional context in comments.

1 Comment

shared link(latter one) doesn't work anymore.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.