better detection of empty database

This commit is contained in:
Athou
2014-08-11 05:33:00 +02:00
parent ff32b0e1c9
commit e8f0cfb4bd
2 changed files with 5 additions and 1 deletions

View File

@@ -28,4 +28,8 @@ public class UserDAO extends GenericDAO<User> {
return newQuery().from(user).where(user.email.equalsIgnoreCase(email)).leftJoin(user.roles, QUserRole.userRole).fetch()
.uniqueResult(user);
}
public long count() {
return newQuery().from(user).count();
}
}

View File

@@ -48,7 +48,7 @@ public class StartupService implements Managed {
new UnitOfWork<Void>(sessionFactory) {
@Override
protected Void runInSession() throws Exception {
if (userDAO.findByName(CommaFeedApplication.USERNAME_ADMIN) == null) {
if (userDAO.count() == 0) {
initialData();
}
return null;