String username = "anAuthenticatedAccount";
HAccount account = (HAccount) session.byNaturalId(HAccount.class).using("username", username).load();
if (account == null) {
account = new HAccount();
account.setUsername(username);
HPerson person = new HPerson();
person.setEmail("email@example.com");
person.setName("aPerson");
person = (HPerson) session.merge(person);
account.setPerson(person);
account = (HAccount) session.merge(account);
}
seamAutowire.use(JpaIdentityStore.AUTHENTICATED_USER, account);