Skip to content
Advertisement

Category: Questions

Spring Data JPA Distinct Returning Duplicate Values

In my Spring boot application I have a query which should return a distinct List of Focus’ (works perfectly in MySQL) However this does not return distinct values, duplicates are contained in the resulting list. Another issue is that I can’t return a whole entity using @Query annotation – changing my query to SELECT DISTINCT(F) FROM Focus F gives the

Java JSON String problem encoding Multipart

I’m developing a REST API that receives a MultipartFormDataInput object (org.jboss.resteasy.plugins.providers.multipart.MultipartFormDataInput), this comes from a form-data Vue.js app. On the data field comes a json string that contains latin accent characters (á, é, í, ó, ú, ñ). When print the json data in Java I get this: Original Json string Json string received in Java What can i do to

Display all the items I have ordered

How to display all the items I have ordered in “Sales Report File”? Like whenever I ordered 2 cookies, It will display on the Sale Report file. I have this code currently.. Answer If you want like a text list of what you have ordered, you can simply create an ArrayList<String> and every time you click on a product you

Sort A List of an Object with other object’s method

In the bellow code, with such classes, how can I sort an ArrayList of Students by the score the got from Courses List? I mean how can I sort a List of a specific class by an attribute of this class which is a child of another class. Answer Your “Student” class is confusing. Based on the name, it sounds

How can I guarantee a thread is safely unlocking a lock upon termination, while all methods already handle it?

A server project, might run for very long time and create many threads. In the following code I ask myself do i have to protect the lock somehow in addition to an overall try catch in method setData(MyData data): note: assuming its thread-safe, i am not really familiar with other reasons or natural disasters that may cause thread termination, like

How to add multiline Strings in Java?

How to make long queries more readable? For example I have this one: And it’s completely unreadable, are there any ways to beautify it? Answer Since Java 15, you can use text blocks:

Advertisement