Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

순서를 보장받으려면 명시적으로 지정을 하여야 합니다. 


SQLJPA

select
*
from
Address
where
generatedAlias0.sex=:param0

order by

age asc,
address asc

public interface AddressRepo extends CrudRepository<Address, Long>{

List<Address> findBySex(String sex, Sort sort);

List<Address> findBySexOrderByAgeDesc(String sex);

...

사용예>

addressRepo.findBySex("남", new Sort(Sort.Direction.ASC, "age","address") );

– ASC : 오름차순 , DESC : 내림차순

Sort의 경우 가변적인 인자값으로 활용될수 있기때문에,  복합 Sort옵션 지정이 가능한 Sort객체를 사용하였습니다.

...

SQL문으로 처리하고 싶으면, 앞장에서 배운 @Query 어노테이션을 통해 쿼리문 수행이 가능합니다.



뷰와 서브쿼리


View 생성/정의View 조회
SQL

CREATE VIEW address_view AS
SELECT t.address_id ,t.name,t.phone_nbr FROM address t;

select * from address_view where name="민수79";
JPA

@Entity
@Immutable
public class AddressView {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "ADDRESS_ID", updatable = false, nullable = false)
private Integer id;

private String name;

private String phoneNbr;

public interface AddressViewRepo extends Repository<AddressView, Long>{
List<AddressView> findByName(String name);
}


Iterable<AddressView> userList = addressViewRepo.findByName("민수97");