mirror of
https://github.com/spring-projects/spring-petclinic.git
synced 2025-05-24 20:39:38 +00:00
commit
18aa56c9c5
4 changed files with 6 additions and 4 deletions
|
@ -45,7 +45,7 @@ public class JpaOwnerRepositoryImpl implements OwnerRepository {
|
||||||
public Collection<Owner> findByLastName(String lastName) {
|
public Collection<Owner> findByLastName(String lastName) {
|
||||||
// using 'join fetch' because a single query should load both owners and pets
|
// using 'join fetch' because a single query should load both owners and pets
|
||||||
// using 'left join fetch' because it might happen that an owner does not have pets yet
|
// using 'left join fetch' because it might happen that an owner does not have pets yet
|
||||||
Query query = this.em.createQuery("SELECT owner FROM Owner owner left join fetch owner.pets WHERE owner.lastName LIKE :lastName");
|
Query query = this.em.createQuery("SELECT DISTINCT owner FROM Owner owner left join fetch owner.pets WHERE owner.lastName LIKE :lastName");
|
||||||
query.setParameter("lastName", lastName + "%");
|
query.setParameter("lastName", lastName + "%");
|
||||||
return query.getResultList();
|
return query.getResultList();
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,7 +43,7 @@ public class JpaOwnerRepositoryImpl implements OwnerRepository {
|
||||||
public Collection<Owner> findByLastName(String lastName) {
|
public Collection<Owner> findByLastName(String lastName) {
|
||||||
// using 'join fetch' because a single query should load both owners and pets
|
// using 'join fetch' because a single query should load both owners and pets
|
||||||
// using 'left join fetch' because it might happen that an owner does not have pets yet
|
// using 'left join fetch' because it might happen that an owner does not have pets yet
|
||||||
Query query = this.em.createQuery("SELECT owner FROM Owner owner left join fetch owner.pets WHERE owner.lastName LIKE :lastName");
|
Query query = this.em.createQuery("SELECT DISTINCT owner FROM Owner owner left join fetch owner.pets WHERE owner.lastName LIKE :lastName");
|
||||||
query.setParameter("lastName", lastName + "%");
|
query.setParameter("lastName", lastName + "%");
|
||||||
return query.getResultList();
|
return query.getResultList();
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,6 +22,8 @@
|
||||||
<!-- import the dataSource definition -->
|
<!-- import the dataSource definition -->
|
||||||
<import resource="datasource-config.xml"/>
|
<import resource="datasource-config.xml"/>
|
||||||
|
|
||||||
|
<context:component-scan
|
||||||
|
base-package="org.springframework.samples.petclinic.service"/>
|
||||||
|
|
||||||
<!-- Configurer that replaces ${...} placeholders with values from a properties file -->
|
<!-- Configurer that replaces ${...} placeholders with values from a properties file -->
|
||||||
<!-- (in this case, JDBC-related settings for the JPA EntityManager definition below) -->
|
<!-- (in this case, JDBC-related settings for the JPA EntityManager definition below) -->
|
||||||
|
@ -40,7 +42,7 @@
|
||||||
<!--
|
<!--
|
||||||
Instruct Spring to perform declarative transaction management
|
Instruct Spring to perform declarative transaction management
|
||||||
automatically on annotated classes.
|
automatically on annotated classes.
|
||||||
|
|
||||||
for mode="aspectj"/ see SPR-6392
|
for mode="aspectj"/ see SPR-6392
|
||||||
-->
|
-->
|
||||||
<tx:annotation-driven/>
|
<tx:annotation-driven/>
|
||||||
|
|
|
@ -20,7 +20,7 @@
|
||||||
- POJOs labeled with the @Controller and @Service annotations are auto-detected.
|
- POJOs labeled with the @Controller and @Service annotations are auto-detected.
|
||||||
-->
|
-->
|
||||||
<context:component-scan
|
<context:component-scan
|
||||||
base-package="org.springframework.samples.petclinic.web, org.springframework.samples.petclinic.service"/>
|
base-package="org.springframework.samples.petclinic.web"/>
|
||||||
|
|
||||||
<mvc:annotation-driven conversion-service="conversionService"/>
|
<mvc:annotation-driven conversion-service="conversionService"/>
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue