Fixed database generation and optimized how entities are persisted.