Connect to two databases using Hibernate [closed] - java

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I was tried to connect two databases in application because I want to refer tables of both databases.Is it possible to connect two or more databases at the same application.I am using Hibernate libraries to connect to the database.

It has nothing to do with JSF because JSF is a view technology. In JDBC you connect to to different databases using getConnection method of DriverManager.In Hibernate you will need to configure one SessionFactory per database in your hibernate.properties or hibernate.cfg.xml. As documentation says,
You configure Hibernate's SessionFactory. SessionFactory is a global
factory responsible for a particular database. If you have several
databases, for easier startup you should use several
configurations in several configuration files.

Related

Spring boot Data source config with JPA [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
For now I am fetching the Datasource properties from the application properties file in spring boot. I want to fetch the data source properties from the DS.xml file placed at the external location on the tomcat 7 server. I want this to be a JNDI based configuration. I am using the JPA repository so it possible to do this with minimum changes to the code.
You can do, but you need to run the application as below command:
java -jar -Dspring.config.location=<external-config-file> myBootProject.jar
please refer the bwlow url for details:
externalise guide URL
You can always use JNDI to configure your data-source with an
application server (like tomcat, weblogic) and then within your app
fetch that data-source and use it.
Some application servers like weblogic provides you a way to config it with GUI and some don't

About jndi database connection [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this question
What is the exact purpose of jndi.Why i need to depends on server for my database connection.I can get the same database connection in normal ojdbc itself.
please help me with that.
Thanks n advance
These are some pointers why i personally prefer JNDI over harcoded configurations in code.
Application can work with any database since it does not need to
bundle the driver.
Multiple applications running on server can use the same connection
pool which might be better use of resources.
This allows container to perform XA transactions in case other
databases are used.

How to achieve database independency when using jdbc [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I want that when I am using jdbc and java to connect to a database it should connect to multiple database
Your question is too broad, but to answer your question to a certain extent, you can do that with multiple JDBC connections to different databases. Each of the database would require a specific connection string and database specific JDBC driver...
Hence, for you to connect to multiple databases using JDBC & Java - you would be able to do that loading the vendor specific drivers and create a connection per database that you would want to connect.

is HikariCP be useful for MongoDB? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
i am trying to use HikariCP for mongodb to get best for db connections.
but HikariCP doesn't have driver for mongodb.
Let me know is that true? is there any possible way to integrate HikariCP with mongodb?
HikariCP is a JDBC connection pool. You can't use it for NoSQL databases. It also doesn't have drivers for anything: it's a connection pool, so it uses JDBC drivers but you have to provide them.

Switching between MongoDB and JPA (Postgres) in the same project [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
In our current project we use MongoDB. Recently there was a request to switch to Postgres.
We don't want to drop MongoDB and just migrate to Postges right away. It would be great to have some sort of a switch in app config to use one or the other.
I know that is possible to have both in the same app (you can have Mongo config and JPA config). Usually it is done to store different domain objects (one type stored and retrieved from Mongo and the other one is stored and retrieved relational database). In these types of projects there are two domain models that serve corresponding persistence mechanisms.
Is there a way to have some sort of an abstract data model, two implementation for it and config switch that will either use MongoDB or Postgres?
Sounds like you should use an interface and then switch to the desired implementation. Not sure if for example Spring's autowiring is the "config switch" you expect, but it should work along those lines.

Categories