What approaches can be used to improve the efficiency of data insertion operations after index implementation?
Java
Read the code, determine what will be output at the end of program execution.
How to view SQL queries sent by JPA/Hibernate to the database?
Why is a foreign key constraint needed? Can't we do without it?
Are you ready to participate in support of services in production, on duty?
Read the code and highlight errors @Component public class AuthorSearchService { @Autowired private AuthorsRepository authorsRepository; @Autowired private StatisticsRepository statisticsRepository; private AlertRestClient arc = new AlertRestClient(); // The query can contain either the full name or part of the name, e.g., "Vadim Panov" or "panov" @Transactional public List<Author> search(String query) { List<Author> authors = authorsRepository.findByNameContainingIgnoreCase(query); Statistics s = statisticsRepository.findById(query).orElse(null); if (s == null) s = new Statistics(query); s.setNumbers(s.getNumbers() + 1); statisticsRepository.save(s); if (s.getNumbers() > 1000 && authors.size() > 1000) { System.out.println("too popular search with too much data, sending an alert..."); arc.send(query, s.getNumbers(), authors.size()); } return authors; } } @Entity @Data public class Author { @Id @GeneratedValue private Long id; private String name; @OneToMany(mappedBy = "author") private List<Book> books; public Author(String name) { this.name = name; } }
The service crashes every few hours with OutOfMemoryError. Where would you start analyzing the problem?
The sock problem: there are heaps of socks of three colors (red, white, black), you pick one by one — how many attempts are guaranteed to get a pair of the same color?
What would you like to do at a new job? What does participation in architectural decisions mean to you?
Tell us about yourself and your experience.
Provide an example of a large business task or integration that you completed entirely on your own.
Tell us more about how you optimized Kafka message processing and synchronous RPC calls.
Will a program with wallet transfers hang in a multithreading task? Why?
Have you ever written a BeanPostProcessor? For what purpose?
Are there any restrictions on indexes? What types of indexes exist (hash, B-tree) and when should they be used?
What will you do if you deployed something and everything crashed — alarms, unclear what is happening?
If the cache times out and requests start flooding the database, how can you reduce the load on the database?
What guarantees does a foreign key provide for data in a relational database? Is it possible to delete a parent record if there are foreign keys referencing it?
Read the code and identify errors ```java @Component public class AuthorSearchService { @Autowired private AuthorRepository authorRepository; @Autowired private StatisticsRepository statisticsRepository; private AlertRestClient arc = new AlertRestClient(); // The query can contain either the full name or part of it, e.g., "Vadim Pavlo" or "pavlo" @Transactional public List<Author> search(String query) { List<Author> authors = authorRepository.findByNameContainingIgnoreCase(query); Statistics s = statisticsRepository.findById(query).orElse(null); if (s == null) s = new Statistics(query); s.setNumbers(s.getNumbers() + 1); statisticsRepository.save(s); if (s.getNumbers() > 1000 && authors.size() > 1000) { System.out.println("too popular search with too much data, sending an alert..."); arc.send(query, s.getNumbers(), authors.size()); } return authors; } } @Entity @Data public class Author { @Id @GeneratedValue private Long id; private String name; @OneToMany(mappedBy = "author") private List<Book> books; public Author(String name) { this.name = name; } } ```
Without Hibernate, how to implement optimistic locking manually using native SQL?