@Entity
@AllArgsConstructor
@NoArgsConstructor
@Data
public class Customer {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
public int id;
public String customerName;
@OneToOne
@JoinColumn(name = "customerType", referencedColumnName = "id")
public CustomerType customerType;
}
@Entity
@AllArgsConstructor
@NoArgsConstructor
@Data
public class CustomerType {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
public int id;
public String customerTypeName;
}
@Repository
public interface CustomerRepository extends CrudRepository<Customer, Integer> {
// ...
}
public List<Tunnel> findByCustomerName(String customerName);
public List<Tunnel> findByCustomerNameAndCustomerTypeId(String customerName, int customerType);
public List<Tunnel> findByCustomerNameAndCustomerType(String customerName, CustomerType customerType);
@Query("SELECT t FROM Customer t WHERE t.customerType = :customerType")
Optional<Iterable<Customer>> select(@Param("customerType") Optional<CustomerType> customerType);