Where does JPA store its actual data entities? - java

Where does JPA store its actual tables? I am using JSP with JPA in NetBeans 7.3.1 on Tomcat and need to backup entire projects including data. Where is the data located? Thank you.

JPA is just an interface specification and doesn't actually "do" or "store" anything; all of that is taken care of by the JPA provider. Most providers (such as Hibernate and EclipseLink) will use a SQL database as the backend, but DataNucleus in particular supports a very large array of backends, including NoSQL databases like BigTable and S3 and regular documents such as spreadsheets.
In your case, you need to look through your application's configuration and find where the DataSource is configured; this is probably either embedded in the war in a .properties file or specified in the Tomcat configuration for the application and made available via JNDI.

Related

How to write a SQL so that it can be run on any database

I have to write an application (in server 1) that will generate a SQL. The SQL will be transferred to some different server (server 2). Another application which is deployed on server 2 will run the query on a database deployed in server 2.
Now there can be different types of database and the query will not be a simple one (may be 200 lines of query). Is there any third party application (like Hibernate) which I can use to create the query may be in a different format (like HQL), which can be transferred to server 2 and the application on server 2 will convert it to a DB specific SQL and run it?
I am using Spring & Java 8 to write the application.
Thanks in advance.
It is not possible for native sql query. But If you use any ORM technology like Hibernate then it is possible. Hibernate dailect will generate different database specific query for you. Though hibernate is an ORM technology it will defines relations with Objects that will represent your database table's. Popularly we call that objects as Entity. SO If you want to use different database then there will be no problem. But you have to change dailelect for different databases.
Why not use ORM - JPA or Hibernate and move queries to configurable different XML which works for each platform/DB? Deploy the XML based on DB...
No shortcut here but if you use ANSI SQL standards which is a platform-independent and is used as a base with most Database systems including Microsoft SQL Server, Oracle, MySQL, IBM DB2 etc you queries should work almost without any issues. Obviously you will loose on added features of DB's provide.

What is a store in spring data jpa?

In the Spring Data JPA documentation, they are often referring to the word store. One such line from documentation is:
If you use the repository abstraction for any other store, you need to change this to the appropriate namespace declaration of your store module. In other words, you should exchange jpa in favor of, for example, mongodb.
What is the actual meaning of store?
Does jpa represent only relational databases in the context of store?
Similarly we can have annotations based on store like #EnableJpaRepositories and #EnableMongoRepositories. Why do we have seperate annotations? I will appreciate clarification.
A "Store" is where you "store" (save) your data.
It's a more generic term covering both databases and non-databases.
Also commonly called a "Data Store", e.g. see Wikipedia:
A data store is a repository for persistently storing and managing collections of data which include not just repositories like databases, but also simpler store types such as simple files, emails etc.
JPA means Java Persistence API, e.g. see Wikipedia:
The Java Persistence API (JPA) is a Java application programming interface specification that describes the management of relational data in applications using Java Platform, Standard Edition and Java Platform, Enterprise Edition.
If you look at the Spring Data site, you'll see that is supports a lot of different data access technologies:
Spring Data JDBC
Spring Data JDBC Extensions
Spring Data JPA
Spring Data LDAP
Spring Data MongoDB
Spring Data Redis
Spring Data REST
Spring Data for Apache Cassandra
Spring Data for Apache Geode
Spring Data for Apache Solr
Spring Data for Pivotal GemFire
Spring Data Couchbase
Spring Data Elasticsearch
Spring Data Envers
Spring Data Neo4J
Spring for Apache Hadoop
JDBC and JPA can both be used to access relational databases.

Generating JPA entities from existing database vs Security

I need to migrate my application from JDBC programing model to use Hibernate. As part of this I would like to use the Annotation based configuration of hibernate. For this I want to generate JPA entities from database. I know how to do this(Using Eclipse Link), but How can I ensure the data is secured when I create JPA entities from my IDE(Eclipse)? Because Ecplise Link is a third party tool, Is there some extra configuration to prevent my database access.
Is there a way achieve this through coding?
You could generate the model from an empty database which contains the structure only and no data.

What's MySQL's role in a JPA project?

I am confused about MySQL's role within a JPA project. For instance, if the project is being made in eclipse IDE, how can this be exported in MySQL? What's MySQL's role in this project? I have researched about this, but I still need some clarification.
JPA is a specification that describes how to save Java objects (called entities) in a database. MySQL is one of many databases a JPA provider can use. You'll specify the database connection at runtime (often in a properties file), and you can generally configure your provider for different databases.
What's MySQL's role in this project?
MySQL is the database: where the data is stored. That's what its role is.
You typically don't need to "export" anything to MySQL from your project. Rather, you set up the JPA configuration file with the backend database settings (database type, hostname, account name, logical database name, etc), and the JPA provider (for example Hibernate) takes care of creating the necessary tables and indexes in your backend database.
MySQL is database management system, meaning it let's you store and query the data in handy manner. Eclipse is devepolment enviroment that helps programmers to create software. JPA is a standard for ORM that let's you map data from the database on the objects (f.e. in Java). There is little connection between these 3.
MySQL, as your research should have told you, is a database (where you store data in a tabular form).
Java Persistence API is an API that handles the mapping between data in a tabular format and an objects as used in a Java program.
This process is know as Object Relational Mapping.
The database is typically created from a set of scripts, so there's not normally an export process, although some JPA implementations such as Hibernate have a pretty good go at creating the database for you based on the mappings to object model without the need for you to write any database scripts.

Using Spring to connect to a database that dynamically changes

I have seen many solutions which all make you first configure statically via XML the different datasources and then use AbstractRoutingDataSource to return back a key which you consume while defining the datasource.
As here: dynamic datasource routing
But my case is different. I dont know how many databases there could be in my web application. I am building an app where each user uploads a small h2 db dump from a desktop app. The web app will download the h2 db dump and then connect to it.
So to make things simple to understand. Each user will have his/her own database file that I need to connect to once the user logs in. Since the number of users are not fixed, I dont know how many databases I will need to connect to, hence I cannot statically configure them in an XML file.
How to go about doing this in Spring? Also, not sure if it helps, these h2 dbs are read only. I am not going to write to them.
This is my configuration.
Maven, Spring MVC, JOOQ, H2 DBs
If you like to change the database changes dynamically, you have to write the UI for database source information and set to the spring config files in version-4.0.

Categories