Hibernate per-user database - java

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

Related

SaaS model with database per user

I want to create SaaS web-application using Spring and Hibernate.
I suppose that we will get many customers(companies) and each company has her own database. All companies have db with same schema. Also we have one administrative db which stores special info, like users, passwords, logins etc. I think that for realization this project i should use hibernate multi-tenancy. But I can't find appropriate examples for my task. This the list of things i want to understand:
Where we can store connections properties(url, port, db name, db user, db password). Should it be property file or administrative db?
I suppose that we can create all beans(dataSource, etc.) for db connection runtime after company's account creation or before first user of company will sign in. Where we can store all created datasources? How we can check if datasource already exist?

How to maintain integrity of a LDAP system together with a relational database?

Currently i'm developing an application which authenticates the users against an external LDAP system. The applications specific data is saved in a relational database though.
My question is if there is a design pattern or something like a best practice to maintain referential integrity in my database concerning the user entries?
One of my ideas was to grab an unique identifier of the user from the LDAP system (once the first login of this user occurs) and store this together with a generated primary key in a table in my database. If I do it like this I would be able to reference the primary key in my other tables. Is this a good approach? Are there any better alternatives?
I'm using an Active Directory, a java backend and a postgres database.
What you described is essentially the approach I've taken for applications that store user login info (or really any LDAP related info) in a separate database.
Basically when they login decode their objectGuid attribute value to get their UUID and use that UUID string to do the rest of their lookups in the database. This helps a lot on user account renames, as you can just lookup the UUID and if it matches then re-sync the user's data (if any else is saved in the DB).

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.

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.

Liferay and its database model

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?

Categories