Skip to content

Instantly share code, notes, and snippets.

@koenighotze
Created September 28, 2015 21:47
Show Gist options
  • Save koenighotze/4e5195adc8671896323a to your computer and use it in GitHub Desktop.
Save koenighotze/4e5195adc8671896323a to your computer and use it in GitHub Desktop.
Basic Controller
package hello;
import javax.enterprise.context.ApplicationScoped;
import javax.inject.Inject;
import javax.inject.Named;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.criteria.CriteriaQuery;
import javax.transaction.Transactional;
import java.util.List;
@Named
@ApplicationScoped
public class HelloController {
@Inject
private Hello hello;
@PersistenceContext
private EntityManager em;
public List<Hello> helloSoFar() {
CriteriaQuery<Hello> cq = this.em.getCriteriaBuilder().createQuery(Hello.class);
cq.select(cq.from(Hello.class));
return this.em.createQuery(cq).getResultList();
}
@Transactional
public void storeName(Hello hello) {
em.persist(hello);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment