Skip to content

Instantly share code, notes, and snippets.

@VineetReynolds
Created January 30, 2016 23:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save VineetReynolds/b37947ed7188a73bd863 to your computer and use it in GitHub Desktop.
Save VineetReynolds/b37947ed7188a73bd863 to your computer and use it in GitHub Desktop.
@Stateless
public class Accounts {
@PersistenceContext
private EntityManager em;
...
public Account getLiabilitiesAccount() {
TypedQuery<Account> findByNameQuery = em.createQuery("SELECT DISTINCT a FROM Account a "
+ "WHERE UPPER(a.name) = 'LIABILITIES'", Account.class);
Account liabiltiesAccount = findByNameQuery.getSingleResult();
return liabiltiesAccount;
}
...
}
@Stateless
public class CustomerAccounts {
@PersistenceContext
private EntityManager em;
@Inject
private Accounts accounts;
...
public CustomerAccount create(String name, Money openingBalance) {
Account liabilitiesAccount = accounts.getLiabilitiesAccount();
...
}
...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment