mirror of
https://github.com/spring-projects/spring-petclinic.git
synced 2025-07-17 21:15:50 +00:00
fix delete() method in JpaPetRepositoryExtImpl
This commit is contained in:
parent
b6dc54f743
commit
720448b506
1 changed files with 44 additions and 39 deletions
|
@ -1,39 +1,44 @@
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
package org.springframework.samples.petclinic.repository.jpa;
|
package org.springframework.samples.petclinic.repository.jpa;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
import java.util.List;
|
||||||
import javax.persistence.EntityManager;
|
|
||||||
import javax.persistence.PersistenceContext;
|
import javax.persistence.EntityManager;
|
||||||
|
import javax.persistence.PersistenceContext;
|
||||||
import org.springframework.beans.factory.annotation.Qualifier;
|
|
||||||
import org.springframework.dao.DataAccessException;
|
import org.springframework.beans.factory.annotation.Qualifier;
|
||||||
import org.springframework.samples.petclinic.model.Pet;
|
import org.springframework.dao.DataAccessException;
|
||||||
import org.springframework.samples.petclinic.repository.PetRepositoryExt;
|
import org.springframework.samples.petclinic.model.Owner;
|
||||||
import org.springframework.stereotype.Repository;
|
import org.springframework.samples.petclinic.model.Pet;
|
||||||
|
import org.springframework.samples.petclinic.model.Visit;
|
||||||
/**
|
import org.springframework.samples.petclinic.repository.PetRepositoryExt;
|
||||||
* @author Vitaliy Fedoriv
|
import org.springframework.stereotype.Repository;
|
||||||
*
|
|
||||||
*/
|
/**
|
||||||
@Repository
|
* @author Vitaliy Fedoriv
|
||||||
@Qualifier("PetRepositoryExt")
|
*
|
||||||
public class JpaPetRepositoryExtImpl extends JpaPetRepositoryImpl implements PetRepositoryExt {
|
*/
|
||||||
|
@Repository
|
||||||
@PersistenceContext
|
@Qualifier("PetRepositoryExt")
|
||||||
private EntityManager em;
|
public class JpaPetRepositoryExtImpl extends JpaPetRepositoryImpl implements PetRepositoryExt {
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@PersistenceContext
|
||||||
@Override
|
private EntityManager em;
|
||||||
public Collection<Pet> findAll() throws DataAccessException {
|
|
||||||
return this.em.createQuery("SELECT pet FROM Pet pet").getResultList();
|
@SuppressWarnings("unchecked")
|
||||||
}
|
@Override
|
||||||
|
public Collection<Pet> findAll() throws DataAccessException {
|
||||||
@Override
|
return this.em.createQuery("SELECT pet FROM Pet pet").getResultList();
|
||||||
public void delete(Pet pet) throws DataAccessException {
|
}
|
||||||
this.em.remove(this.em.contains(pet) ? pet : this.em.merge(pet));
|
|
||||||
}
|
@Override
|
||||||
|
public void delete(Pet pet) throws DataAccessException {
|
||||||
}
|
String petId = pet.getId().toString();
|
||||||
|
this.em.createQuery("DELETE FROM Visit visit WHERE pet_id=" + petId).executeUpdate();
|
||||||
|
this.em.createQuery("DELETE FROM Pet pet WHERE id=" + petId).executeUpdate();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue