Skip to content

Commit 4f0a8ce

Browse files
authored
Bael 6317 (#15978)
* 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
1 parent f99982e commit 4f0a8ce

File tree

3 files changed

+127
-0
lines changed

3 files changed

+127
-0
lines changed
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
package com.baeldung.queryhint;
2+
3+
import java.sql.Date;
4+
5+
import javax.persistence.Entity;
6+
import javax.persistence.GeneratedValue;
7+
import javax.persistence.GenerationType;
8+
import javax.persistence.Id;
9+
import javax.persistence.NamedQueries;
10+
import javax.persistence.NamedQuery;
11+
import javax.persistence.QueryHint;
12+
import javax.persistence.Table;
13+
14+
import org.springframework.data.jpa.repository.QueryHints;
15+
16+
@Entity
17+
@Table(name = "app_user")
18+
@NamedQueries({ @NamedQuery(name = "selectEmployee", query = "SELECT e FROM Employee e", hints = @QueryHint(name = "org.hibernate.fetchSize", value = "50")) })
19+
public class Employee {
20+
21+
@Id
22+
@GeneratedValue(strategy = GenerationType.IDENTITY)
23+
private Long id;
24+
private String username;
25+
private String password;
26+
private String gender;
27+
private String name;
28+
private Date joinDate;
29+
private int age;
30+
31+
public Long getId() {
32+
return id;
33+
}
34+
35+
public void setId(Long id) {
36+
this.id = id;
37+
}
38+
39+
public String getUsername() {
40+
return username;
41+
}
42+
43+
public void setUsername(String username) {
44+
this.username = username;
45+
}
46+
47+
public String getPassword() {
48+
return password;
49+
}
50+
51+
public void setPassword(String password) {
52+
this.password = password;
53+
}
54+
55+
public String getGender() {
56+
return gender;
57+
}
58+
59+
public void setGender(String gender) {
60+
this.gender = gender;
61+
}
62+
63+
public String getName() {
64+
return name;
65+
}
66+
67+
public void setName(String name) {
68+
this.name = name;
69+
}
70+
71+
public Date getJoinDate() {
72+
return joinDate;
73+
}
74+
75+
public void setJoinDate(Date joinDate) {
76+
this.joinDate = joinDate;
77+
}
78+
79+
public int getAge() {
80+
return age;
81+
}
82+
83+
public void setAge(int age) {
84+
this.age = age;
85+
}
86+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package com.baeldung.queryhint;
2+
3+
import org.springframework.boot.SpringApplication;
4+
import org.springframework.boot.autoconfigure.SpringBootApplication;
5+
6+
@SpringBootApplication
7+
public class EmployeeApplication {
8+
9+
public static void main(String[] args) {
10+
SpringApplication.run(EmployeeApplication.class);
11+
}
12+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package com.baeldung.queryhint;
2+
3+
import java.util.List;
4+
5+
import javax.persistence.QueryHint;
6+
7+
import org.springframework.data.jpa.repository.JpaRepository;
8+
import org.springframework.data.jpa.repository.QueryHints;
9+
import org.springframework.stereotype.Repository;
10+
11+
@Repository
12+
public interface EmployeeRepository extends JpaRepository<Employee, Long> {
13+
14+
@QueryHints(value = { @QueryHint(name = "org.hibernate.fetchSize", value = "50") })
15+
List<Employee> findByGender(String gender);
16+
17+
@QueryHints(value = { @QueryHint(name = "javax.persistence.query.timeout", value = "5000") })
18+
List<Employee> findActiveEmployees(long inactiveDaysThreshold);
19+
20+
@QueryHints(value = { @QueryHint(name = "jakarta.persistence.cache.retrieveMode", value = "USE"),
21+
@QueryHint(name = "jakarta.persistence.cache.storeMode", value = "USE") })
22+
List<Employee> findEmployeesByName(String name);
23+
24+
@QueryHints(@QueryHint(name = "org.hibernate.readOnly", value = "true"))
25+
Employee findByUsername(String username);
26+
27+
@QueryHints(value = { @QueryHint(name = "org.hibernate.comment", value = "Retrieve employee older than specified age\"") })
28+
List<Employee> findByAgeGreaterThan(int age);
29+
}

0 commit comments

Comments
 (0)