Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 5 additions & 7 deletions src/main/java/org/springframework/samples/petclinic/vet/Vet.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@

import org.springframework.beans.support.MutableSortDefinition;
import org.springframework.beans.support.PropertyComparator;
import org.springframework.samples.petclinic.model.Person;

import jakarta.persistence.Entity;
import org.springframework.samples.petclinic.model.Person;import jakarta.persistence.Entity;
import jakarta.persistence.FetchType;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.JoinTable;
Expand All @@ -42,10 +40,10 @@
* @author Arjen Poutsma
*/
@Entity
@Table(name = "vets")
public class Vet extends Person {
@Table(name = "vets")public class Vet extends Person {

@ManyToMany(fetch = FetchType.EAGER)
@ManyToMany(fetch = FetchType.LAZY)
@BatchSize(size = 100)
@JoinTable(name = "vet_specialties", joinColumns = @JoinColumn(name = "vet_id"),
inverseJoinColumns = @JoinColumn(name = "specialty_id"))
private Set<Specialty> specialties;
Expand Down Expand Up @@ -76,4 +74,4 @@ public void addSpecialty(Specialty specialty) {
getSpecialtiesInternal().add(specialty);
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@
import org.springframework.dao.DataAccessException;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.Repository;
import org.springframework.transaction.annotation.Transactional;

import java.util.Collection;
import java.util.Collection;import java.util.Collection;

/**
* Repository class for <code>Vet</code> domain objects All method names are compliant
Expand All @@ -34,25 +35,48 @@
* @author Juergen Hoeller
* @author Sam Brannen
* @author Michael Isvy
*/
public interface VetRepository extends Repository<Vet, Integer> {

/**
* Retrieve all <code>Vet</code>s from the data store.
* @return a <code>Collection</code> of <code>Vet</code>s
*/
@Transactional(readOnly = true)
@Cacheable("vets")
Collection<Vet> findAll() throws DataAccessException;

/**
* Retrieve all <code>Vet</code>s from data store in Pages
* @param pageable
* @return
* @throws DataAccessException
*/
@Transactional(readOnly = true)
@Cacheable("vets")
Page<Vet> findAll(Pageable pageable) throws DataAccessException;

}
*/public interface VetRepository extends Repository<Vet, Integer> {

/**
* Retrieve all <code>Vet</code>s from the data store.
* @return a <code>Collection</code> of <code>Vet</code>s
*/
@Query("SELECT DISTINCT vet FROM Vet vet LEFT JOIN FETCH vet.specialties")
@Transactional(readOnly = true)
@Cacheable("vets")
Collection<Vet> findAll() throws DataAccessException;

/**
* Retrieve all <code>Vet</code>s with specialties from the data store.
* @return a <code>Collection</code> of <code>Vet</code>s
*/
@Query("SELECT DISTINCT vet FROM Vet vet LEFT JOIN FETCH vet.specialties")
@Transactional(readOnly = true)
@Cacheable("vets")
Collection<Vet> findAllWithSpecialties() throws DataAccessException;

/**
* Retrieve all <code>Vet</code>s from data store in Pages
* @param pageable
* @return
* @throws DataAccessException
*/
@Query(value = "SELECT DISTINCT vet FROM Vet vet LEFT JOIN FETCH vet.specialties",
countQuery = "SELECT COUNT(DISTINCT vet) FROM Vet vet")
@Transactional(readOnly = true)
@Cacheable("vets")
Page<Vet> findAll(Pageable pageable) throws DataAccessException;

/**
* Retrieve all <code>Vet</code>s with specialties from data store in Pages
* @param pageable
* @return
* @throws DataAccessException
*/
@Query(value = "SELECT DISTINCT vet FROM Vet vet LEFT JOIN FETCH vet.specialties",
countQuery = "SELECT COUNT(DISTINCT vet) FROM Vet vet")
@Transactional(readOnly = true)
@Cacheable("vets")
Page<Vet> findAllWithSpecialties(Pageable pageable) throws DataAccessException;

}