Posty

Wyświetlanie postów z marzec, 2020

Spring/Hibernate optimization: JPA with @OneToOne mapping

Lately I wanted to see how Hibernate actually construct sql statements. And it seems like it makes somtimes unnecessary joins. Those are my playground's results. Repo:  https://github.com/toficzak/social-app Setup: Post repository consists of 3 methods: Sql generated by Hibernate: How did I measure execution time:    Simple select measure By author id: 1952090.938 By author (User provided): 1048579.671 By author (User not provided): 1021450.464 By custom query: 935087.347 My custom JPA query is the fastest option - it skips whole User join section. But why is it needed at all? Seems like an error in my design.

Testing: jUnit's TemporaryFolder

Testing: jUnit's TemporaryFolder with Simple CSV generator The problem Lately I had a question in my head: how to test a method, which output is a file?  Should I divide creation of file from creation of content and test only the latter part? Well, usually I would like to call a method "generateReport" or retrieveFileByHash(), which encapsulate all file-connected operations and return simple java.io.File. In other words, my service classes looks like this: Interface (like ReportGenerator) one method returns: File Concrete class (like DefaultReportGenerator) one public implementation of interface method, (like generateReport()) returns: File set of private methods returns: whatever is needed to create File With such services, file's content creation is separated from File creation: Interface - ReportGenerator method: generateReport() returns File Concrete Class - DefaultReportGenerator method: implementation of generateRepor