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
7 changes: 7 additions & 0 deletions spring-data-jpa-1/initial/src/main/java/cholog/Customer.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
package cholog;

import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;

@Entity
public class Customer {

@Id @GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private String firstName;
private String lastName;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
package cholog;

public interface CustomerRepository {
import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface CustomerRepository extends CrudRepository<Customer, Long> {

List<Customer> findByLastName(String lastName);

List<Customer> findByLastNameIgnoreCase(String lastName);

List<Customer> findByLastNameOrderByFirstNameDesc(String lastName);
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ public class EntityManagerTest {

@Autowired
private JdbcTemplate jdbcTemplate;
@Autowired
private CustomerRepository customerRepository;

/**
* 비영속 -> 영속
Expand All @@ -34,12 +36,12 @@ void persist() {
*/
@Test
void flush() {
String sqlForSelectCustomer = "select * from customer where id = 1";

Customer customer = new Customer("Jack", "Bauer");
entityManager.persist(customer);
customer.updateFirstName("Danial");

String sqlForSelectCustomer = "select * from customer where id = " + customer.getId();

Comment on lines +43 to +44

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

저도 테스트코드 뭔가 이상하다고 생각했는데 저만 그렇게 생각한게 아니었군요..

Customer savedCustomer = jdbcTemplate.query(sqlForSelectCustomer, rs -> {
rs.next();
return new Customer(
Expand Down