I am using SQLite3 and Hibernate with Java. Can I somehow load the whole database in memory or fetch all data from the database so that I can access mapped objects fastest? For example if we have a Company and Employee classes and in Company we've mapped the Employees as company.getEmployees(). I would like to fetch all companies from the database and later when I call this method I'd like to get the employees immediately. So is there a way to preload them? Further, if employee is mapped to other objects, can I preload them too? To summarize, I'd like to load the whole database and use the ORM to access the data. Thanks!
Asked
Active
Viewed 1,473 times
2 Answers
2
If your goal is simply blazing performance you have several options:
- Configure Hibernate 2nd-level cache
- In addition to prior point, configure query cache if your data doens't change much.
- Instead of SQLite use HSQLDB or H2 in-memory SQL databases in embedded mode
- Use ObjectDB with a large shared cache. JPA compliant OODB.
- Use MongoDB. A very fast in-memory NoSQL solution
I suggest ObjectDB if you aren't required to use SQL.
(EDITS: Removed eager fetching, added query cache.)

mikeslattery
- 4,039
- 1
- 19
- 14
-
I think he'll get a lot better by implementing the first step only. I agree with the rest though, but if its too much effort, configuring a good cache will do a good job. – Sinisha Mihajlovski Dec 13 '12 at 15:48
0
Set all relationships in your entity classes to eager. If you are using JPA annotations:
public class Company{
private List<Employee> employeeList;
@ManyToMany(fetch = FetchType.EAGER)
public List<Employee> getEmployeeList() {
return employeeList;
}
}
This will fetch all the employees automatically when you retrieve a company from database. Please note this could affect the performance dramatically.

Eugenio Cuevas
- 10,858
- 3
- 29
- 51
-
-
Totally, as long as it is the same object. Just curious, why would you do that? Take a look at [memcached](http://memcached.org/), it seems a better approach to have an in-memory database – Eugenio Cuevas Dec 13 '12 at 15:30
-
Cause my database is small (~3 mb) and I use every bit of data stored in it. Thanks! – Dec 13 '12 at 15:36