Liferay and its database model - java

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?

Related

Separation of database(JPA) objects from data for the frontend in SpringBoot

I am currently developing a full-stack web application as a hobby project.
My tech stack is:
MySql Database
SpringBoot RestApi backend with JPA for the database interaction
Vue frontend
I have already modelled the database and created jpa entities for all the tables in the database. The data model includes some bi-directional relationships (many to many relationships). I then started creating some API Endpoints for the frontend to interact with, but I have some problems with deciding how I want the data to be serialized and sent to the frontend.
In most of the tutorials and examples the objects that directly resemble the database objects are serialized and then sent to the frontend. But I dont want that, mainly because of the bi-directional relationships which create unserializable recursions, but also because not all the data of an object from the database is meant to be sent to the frontend.
So I want to know how the separation/conversion between the database(jpa) objects and the objects that are serialized and then sent to the frontend is usually achieved.
I had some ideas, but I dont know how feasible they are in the real world:
Idea 1: Create separate frontend classes of all entities which only include the data which has to be sent to the frontend.
But this possibly creates additional problems because of the continuous conversion between classes in every request/answer.
Idea 2: Only send the "raw" object with all relations only as Ids, and just block all the "unwanted" data from serialization.
In this case the frontend now has to do way more requests to the backend in order to resolve all those ids to the required data.
Idea 1 is exactly how it is usually done. The "frontend classes" as you called them are usually called Data Transfer Objects (DTOs) which are essentially "views" of the data stored in the DB tailored specifically for effectiveness of transfer from backend to frontend (via aggregation of multiple related entities) and ease of use (display) by the frontend.
The problem of conversion is a known one and is quite successfully solved by so called "mappers" that allow for (semi-)automatic conversion between DB entities and DTOs. One great example of such a mapper is MapStruct (https://mapstruct.org/documentation/stable/reference/html/) which nicely integrates with Spring and Lombok and has support in IntelliJ Idea.

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.

Hibernate per-user database

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

Multiple Schema or Single Schema for Cloud App?

I've a question about how to manage database for clients for a Cloud App. I want to create a Cloud ERP on Spring and Hibernate but I'm not sure how to manage the database. Someone says me that should create a clone schema for every client to manage properly and secure the data, but I'm not sure that should be that 'cause that mean have a powerful database server. In the other hand exist the posibility to have a single schema to all users but that could be a lots of problem in management.
Please give me some advices.
If the data you are dealing with are totally different from customer to customer, then it is better to use cloned schemas for every customer.

Categories