* BAEL-7490 read write file in separate thread

* Change the to try resources

* Update the code to sync with article

* BAEL-6317 Query Hint

* BAEL-6317 check if date object equals to yesterday

* Wrong file
This commit is contained in:
Wynn Teo 2024-03-04 00:01:05 +08:00 committed by GitHub
parent f99982eb41
commit 4f0a8ce5d9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 127 additions and 0 deletions

View File

@ -0,0 +1,86 @@
package com.baeldung.queryhint;
import java.sql.Date;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.QueryHint;
import javax.persistence.Table;
import org.springframework.data.jpa.repository.QueryHints;
@Entity
@Table(name = "app_user")
@NamedQueries({ @NamedQuery(name = "selectEmployee", query = "SELECT e FROM Employee e", hints = @QueryHint(name = "org.hibernate.fetchSize", value = "50")) })
public class Employee {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private String username;
private String password;
private String gender;
private String name;
private Date joinDate;
private int age;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getGender() {
return gender;
}
public void setGender(String gender) {
this.gender = gender;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Date getJoinDate() {
return joinDate;
}
public void setJoinDate(Date joinDate) {
this.joinDate = joinDate;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
}

View File

@ -0,0 +1,12 @@
package com.baeldung.queryhint;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class EmployeeApplication {
public static void main(String[] args) {
SpringApplication.run(EmployeeApplication.class);
}
}

View File

@ -0,0 +1,29 @@
package com.baeldung.queryhint;
import java.util.List;
import javax.persistence.QueryHint;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.QueryHints;
import org.springframework.stereotype.Repository;
@Repository
public interface EmployeeRepository extends JpaRepository<Employee, Long> {
@QueryHints(value = { @QueryHint(name = "org.hibernate.fetchSize", value = "50") })
List<Employee> findByGender(String gender);
@QueryHints(value = { @QueryHint(name = "javax.persistence.query.timeout", value = "5000") })
List<Employee> findActiveEmployees(long inactiveDaysThreshold);
@QueryHints(value = { @QueryHint(name = "jakarta.persistence.cache.retrieveMode", value = "USE"),
@QueryHint(name = "jakarta.persistence.cache.storeMode", value = "USE") })
List<Employee> findEmployeesByName(String name);
@QueryHints(@QueryHint(name = "org.hibernate.readOnly", value = "true"))
Employee findByUsername(String username);
@QueryHints(value = { @QueryHint(name = "org.hibernate.comment", value = "Retrieve employee older than specified age\"") })
List<Employee> findByAgeGreaterThan(int age);
}