Skip to main content

All Questions

0 votes
0 answers
114 views

I can't catch DataIntegrityViolationException with @Transactional in an update service method

This JUnit tests fails public void shouldFailToEditUserTypeWithoutType() { UserType userType = new UserType(null, "dd"); userType.setType(null); Exception exception = ...
José Lisboa's user avatar
0 votes
2 answers
648 views

Why aren't rows being inserted into the H2 Db from my script even though the drop table and create table is happening?

Why aren't rows being inserted into the H2 Db from my script even though the drop table and create table is happening? Hibernate: drop table if exists encouragement CASCADE Hibernate: create table ...
likejudo's user avatar
  • 3,574
0 votes
1 answer
334 views

Spring data JPA Junit tests work apart but don't work together

I'm going to test my app with next Junit tests: @DataJpaTest class UserNameTest { @Autowired private UserNameRepo repo; private UserName userName; @Test public void createUserName(...
Ensei's user avatar
  • 35
0 votes
1 answer
658 views

Does @Transactional annotation on test methods rollback every transaction in the annotated method before it gets to the end?

I am writing a test which confirms that trying to create a user with an email which already exists results in a failure. The database has been set up to have a unique constraint on the email field. I ...
Harsha Limaye's user avatar
1 vote
0 answers
758 views

"java.lang.IllegalStateException: Cache[default-update-timestamps-region] is closed"

Running JUnit tests in Eclipse STS for a Spring Boot 2.5 application with Spring Data JPA occasionally triggers the trace below at the end the tests. Running the same tests from the command line via ...
Jan Nielsen's user avatar
  • 11.4k
0 votes
2 answers
585 views

NullPointerException while accessing nested objects of Root object in JPA

I am writing test cases using Mockito (not powermock) for my Hibernate's Predicate class. My method is as follows- buildXYZQuery(Root<?> root, Filter filter, CriteriaBuilder cb, Predicate where, ...
Aniruddh Dwivedi's user avatar
0 votes
0 answers
271 views

JUnit testing hibernate validation in Spring boot application

I have little pet project, it can make daily schedule for students and teachers. Now I've added hibernate validation in my project. When application work and I enter wrong value into field I got ...
Evgenii  Stepanov's user avatar
0 votes
1 answer
194 views

Always getting a empty object in unitTest JPA/Hibernate

I am currently trying if my functions work with my current database but I keep getting an empty object back. My Test is the following: @Test public void findJobOfferByIdReturnsCorrectJobOffer() { ...
Jens Panis's user avatar
-1 votes
1 answer
691 views

The easiest Junit test for connection to database in spring boot application

I started to write application with friend and I would like to write a simple test for database connection. He is owner of server so test will be red now of course but when he set up database and ...
Michu93's user avatar
  • 5,504
2 votes
1 answer
1k views

How to order execution of controller test classes in Junit5 / spring boot?

In my entities I have bidirectional one-to-many relation and I would like to write integration tests with mock.mvc. However, before adding parent, I cannot add child. For this reason, I would like to ...
Aksoy's user avatar
  • 101
0 votes
2 answers
474 views

Java Hibernate LazyInitializationException only when running with JUnit only

I am using Java + Spring boot(Ver 2.1.16) + Hibernate + JPA for an API project. I have several models with several OneToMany relationships. I haven't mentioned a fetch type but as I know it's Eager in ...
Udara Seneviratne's user avatar
0 votes
0 answers
209 views

Spring data join query not fetching results in junit

I have an SpringBoot application in which I have defined an entity as given below @Entity public class Organisation { @Id @GeneratedValue @JsonIgnore private Long id; private String entityId; ...
dev Joshi's user avatar
  • 385
1 vote
1 answer
1k views

Lazy loaded collection empty in junit

I have an SpringBoot application in which I have defined an entity as given below @Entity public class Organisation { @Id @GeneratedValue @JsonIgnore private Long id; private String entityId; @...
dev Joshi's user avatar
  • 385
3 votes
1 answer
831 views

How to acquire current session in transactional @Test for SpringBoot?

Spring documentation warns about False Positives in Transactional tests and suggest the following: // ... @Autowired SessionFactory sessionFactory; @Transactional @Test // no expected exception! ...
Koray Tugay's user avatar
  • 23.5k
0 votes
0 answers
376 views

SpringBoot testing Docker database

So I have this SpringBoot RESTful server connecting to a Docker image database. If database is down it it sends an error message via response. I would very much like to test it - I created a jUnit+...
k-wasilewski's user avatar
  • 4,455

15 30 50 per page