F4F
JCHJava Community | Help. Code. Learn.
•Created by F4F on 1/24/2025 in #java-help
ThreadPoolTaskExecutor - Configuration way.
Helo, what is the best way to configure ThreadPoolTaskExecutor and why?
1 -
@Bean(name = "thisIsBeanName")
public ThreadPoolTaskExecutor taskExecutor(ThreadProperties threadProperties) {
ThreadPoolTaskExecutor threadPoolTaskExecutor = new ThreadPoolTaskExecutor();
properties..
2 - private final ThreadProperties threadProperties;
@Bean(name = "thisIsBeanName")
public ThreadPoolTaskExecutor threadPoolTaskExecutor() {
ThreadPoolTaskExecutor threadPoolTaskExecutor = new ThreadPoolTaskExecutor();
properties...
28 replies
JCHJava Community | Help. Code. Learn.
•Created by F4F on 12/7/2024 in #java-help
N+1 Hibernate.
I've got problem with fetching data. Here is my code:
@NoArgsConstructor
@AllArgsConstructor
@Getter
@Setter
@Entity
@SuperBuilder
@DiscriminatorColumn(name = "dtype")
public abstract class Person{
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer id;
private String name;
private String surname;
}
@Entity
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
@SuperBuilder
public class Employee extends Person {
@OneToMany(mappedBy = "employee")
private List<Position> positions = new ArrayList<>();
}
@NoArgsConstructor
@AllArgsConstructor
@Getter
@Setter
@Entity
@SuperBuilder
@ToString
public class Position {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer id;
@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "employee_id")
private Employee employee;
private String position;
private LocalDate startDate;
private LocalDate endDate;
}
@Transactional(readOnly = true)
public Page<PersonDto> findAll(Pageable pageable, Map<String, String> params) {
Specification<Person> filter = FilterSpecification.byCriteria(params);
return personRepository.findAll(filter, pageable)
.map(person -> creationStrategies.get(person.getType()).toDto(person));
}
I've got one superclass like Person becauseI can create a lot of person typelike Employee, alien, kid, retiree with deflaut params. But when I'm fetching all the people using findAll from JPA I'v got this problem:
Hibernate: select distinct p10.id,p1_0.dtype,p1_0.email,p1_0.height,p1_0.name,p1_0.person_number,p1_0.surname,p1_0.type,p1_0.version,p1_0.weight,p1_0.pension_amount,p1,p1_0.university_name,p1_0.year_of_study from person p1_0 where 1=1 offset ? rows fetch first ? rows only Hibernate: select p1_0.employee_id,p1_0.id,p1_0.end_date,p1_0.position,p1_0.salary,p1_0.start_date from position p1_0 where p1_0.employee_id=?
I'm tried fetchType.Eager, Batch and all of them doesn't work.
5 replies
JCHJava Community | Help. Code. Learn.
•Created by F4F on 4/6/2023 in #java-help
Interface
Hello! I have question about methods in interface.
I have got class like triangle, square this class implements my interface "Figures"
In interface I have got methods " double countArea();"
how I can create List method in interface?
Is this good idea -> "List<Figures> areasSmallerThan();" ?
Thanks for your answers.
10 replies