Java tutorial
/** * Copyright 2014 Nicotina Estudio * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. **/ package com.sct.descubriendoturuta.service; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import com.sct.descubriendoturuta.model.Person; import javax.persistence.EntityManager; import javax.persistence.PersistenceContext; import javax.persistence.criteria.CriteriaQuery; import javax.persistence.criteria.Root; import java.util.List; @Service public class PersonServiceImpl implements PersonService { @PersistenceContext EntityManager em; @Transactional public void addPerson(Person person) { em.persist(person); } @Transactional public List<Person> listPeople() { CriteriaQuery<Person> c = em.getCriteriaBuilder().createQuery(Person.class); c.from(Person.class); return em.createQuery(c).getResultList(); } @Transactional public void removePerson(Integer id) { Person person = em.find(Person.class, id); if (null != person) { em.remove(person); } } }