Date now = new Date();
account.setCreated(now);
account.setLastModified(now);
account.setClosed(Boolean.FALSE);
UserDetails user = UserDetails.findCurrentUser();
user.addAccount(account);
if (account.getFavorite() == null) {
account.setFavorite(Boolean.FALSE);
}
if (account.getAccountType() != null) {
account.setAccountType(AccountType.entityManager().getReference(AccountType.class, account.getAccountType().getId()));