Java Community | Help. Code. Learn.

JCH

Java Community | Help. Code. Learn.

With more than 20,000 members, join one of the biggest and most active Java Communities on Discord! ☕

Join

java-help

❓︱qotw-answers

how to check if record exists in DB table?

hey guys. can smb help me out? in my repo class i have this:
@Query(value = "select count(1) from my_tablewhere transaction_id= :transactionId",nativeQuery = true)
boolean existsByTransactionId(@Param("transactionId") String transactionId);
@Query(value = "select count(1) from my_tablewhere transaction_id= :transactionId",nativeQuery = true)
boolean existsByTransactionId(@Param("transactionId") String transactionId);
...

service deletes DB records, but i still get `No results were returned by the query`

hey guys. can smb help me out? i have this service: ```java public void createPaymentpaymentReversal(PaymentDTO paymentReversalRequest) throws NoEarlierPaymentException { Optional<Payment> earlierPayment=paymentRepository.findByTransactionId(paymentReversalRequest.getTransactionId()); ...

apache Mina sshd

If anyone had expierence with Apache Mina and setting up a ssh server please tell me. I got an issue where my client session are mixxed up if there’s more than 1 of them… (the 2nd user becomes the first) Tell me guys I am tired of posting the code...

How do I use UserDetailsService properly? Where do I define it exactly?

I was going through spring security's docs and found this ```java @Configuration @EnableWebSecurity...

Spring app doesn't read environmental variables from .env

I have .env file in my project root folder along with pom.xml. Contents: ``` APP_PASSWORD=my-app-password DATABASE_PASSWORD=Tomasm21-xi DATABASE_USERNAME=Tomasm21...

RestApi Access Problem

When i try to access the Rest Api from postman then i got the html of login i even permit the enpoint of api ```@RestController @RequestMapping("/api/Student") @CrossOrigin(origins = "http://localhost:3000") public class RestApplication { ...

Spring Boot Security / Request = 500

Hello guys, I'm a beginner here who's trying Spring Boot security. I'm trying to sign in with the httpSecurity but when I do my sign-in request, SPring boot redirects me to the famous ```Whitelabel Error Page This application has no explicit mapping for /error, so you are seeing this as a fallback....

why use Optional<MyClass> if you cant call any methods that MyClass has?

hey guys. can smb explain to me what wrong? im trying to retrieve an object from DB: Optional<Payment> earlierPayment=paymentRepository.findByTransactionIdAndAmount(paymentConfirmationRequest.getTransactionId(), paymentConfirmationRequest.getAmount());. and for some reason i cant call any getters that my Payment entity has. does it mean that id need to change the return type of findByTransactionIdAndAmount from Optional<Payment> to just Payment? and then id loose the advantage Optional gives me. that doesnt make any sense 😦 any help? thanks...

how to convert long to int

hi fellas. i was wondering i you could help me. in postgre db i have a field order_time. its data type is int4. there are a couple of records, where order_time is 1536936174. so i have a couple of questions: 1. i was wondering how to set this field value, when im doing insert in my Java code? 2. why the date is stored in a column that has datatype of int4? why not date or datetime? 3. in java code i see that my entity is private Long orderTime, so does that mean theres a mistake in the code and i need to use Long in the database too? or do i use int in my Java code? ...

Mocking fails for some reason

```java @SpringBootTest @TestPropertySource(locations = "classpath:application-test.properties") @DirtiesContext(classMode = DirtiesContext.ClassMode.BEFORE_EACH_TEST_METHOD) class UserServiceTests {...

dependency isnt injected into my service

hey guys. can smb help me out. i have a service ```java @Service @Slf4j public class MyService {...

Failing test under misterious circumstances

https://github.com/KoblizekXD/notecz-backend/blob/4a70434b5c139b2d6bf5c6953fbf49a92cebded5/src/test/java/lol/koblizek/notecz/api/user/UserServiceTests.java#L49 this test seems to be failing, altough when i try to run UserRepositoryTests and test the validation, it correctly throws an exception, but here the saveAndFlush just returns null......

Trying to load a Font from resources throws a BufferUnderflowException

I am trying to load a Selawik font from my project's resources with following code: ```java try (InputStream is = getClass().getResourceAsStream("/fonts/selawk.ttf")) { Font selawik = Font.createFont(Font.TRUETYPE_FONT, is); }...

some help needed with fixing circular dependencies

hey guys. can smb help me out with fixing circular dependencies? ``` The dependencies of some of the beans in the application context form a cycle: infoRestController...

do i need to return DTO from my controller when handling errors?

hey guys. i want to ask for some help. in my service i do some checks and throw custom exceptions which later i handle in RestResponseEntityExceptionHandler. it looks like this: ```java @ControllerAdvice @Slf4j public class RestResponseEntityExceptionHandler extends ResponseEntityExceptionHandler {...

Spring Boot Microservices with JWT Issues

I try to implement an example of Spring Boot Microservices with JWT. I have some problems following: 1 ) I cannot run all integration tests of product service even if I defined bearer token 2 ) After login and get access token, I cannot send any request to product service. I got 500 Internal Server Error. How can I fix it? I hope you can help me? Here is the repo : https://github.com/Rapter1990/springbootmicroserviceswithsecurity...

Help with Lombok

I am making utility methods for sending discord webhooks. my goal is this: ```java DiscordWebhook webhook = DiscordWebhook.builder() .webhookURI(new URI("https://discord.com/api/webhooks/123"))...

Spring Boot @Mapping gives no read accessor error

Hello! I'm trying to use @mapping to map a DTo from entities My Main DTO is ``` public class MainDto {...

how to properly handle case when theres no records in the db table?

hey guys. so i have my CustomerRepo in my service and i want to handle a scenario when there are no customers with given id. so far i have this: ```java Optional<Customer> customer=customerRepository.findById(Long.valueOf(paymentInformationRequest.getClientId())); if (customer.isEmpty()) { log.info("BGWService.createPaymentInformation. no customer with id: {}", paymentInformationRequest.getClientId());...