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.
Related
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.
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.
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.
I am currently working on a (website-)project in which I intent to keep each user's data separate from another. The main database (containing information about the user (user, password etc)) is a MySQL database.
Per-user there is a lot of data that needs to be stored and is important not to mix up with another user his/her data. Now I was thinking of using a sqlite db per user but I found out Hibernate (the db framework of my choice) does support sqlite by default.
I found http://code.google.com/p/hibernate-sqlite/ as an option. But I was wondering if there are any other database types with which it is easy to create one per-user, and preferably compatible with hibernate? If so, which ones?
check out Multi-tenancy in hibernate
We want to use Liferay but is it possible to create our own database tables with foreign keys and integrity?
Liferay seems to create a lot of stuff and has control over the DB, so I want to know if we'll get into problems trying to do this.
thank you!
Of course you can. You will spend most of the time developing portlets and plugins, that have their own database model (in the same database) that is independent of the portal database model.
You have a choice to use so called Service Builder, which is a source code generator that among other things creates DDL scripts of your data model based on metadata definition. Again, even this data model doesn't depend on Portal database and is based on Hibernate/JPA.
Another choice is to not use Service Builder at all and utilize some JPA implementation or Hibernate directly.
Sometimes one just needs to use portal tables (User, Resources, etc.) and persist data into them but for that you have a service layer already available for you.
There are no foreign keys in the liferay schema and you can't create foreign key relationships with the Liferay service builder.
See Where are the foreign keys?