Created
September 28, 2015 21:47
-
-
Save koenighotze/4e5195adc8671896323a to your computer and use it in GitHub Desktop.
Basic Controller
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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