Win a copy of Reactive Streams in Java: Concurrency with RxJava, Reactor, and Akka Streams this week in the Reactive Progamming forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Ganesh Patekar

Spring Data JPA not persisting entity

 
Ranch Hand
Posts: 640
2
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am using Spring Data Jpa for my persistence layer and facing an issue where the code is able to fetch(read) the records but not inserting the entities to DB. Below is my code.
I don't know what wrong I am doing, please help.




 
Puspender Tanwar
Ranch Hand
Posts: 640
2
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Forgot to paste the Test case. Here it is:
[code=java][@ContextConfiguration(classes = {PersistenceJpaConfig.class, ContextConfig.class})
@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest
public class TestJPA {

@Autowired
private UserJpaRepository userJpaRepository;

@Test
@Transactional
public void insertUser() {
User user1 = new User("puspender@fake.com","puspender", false, "12345");
System.out.println("saving user");
assertNotNull(userJpaRepository.save(user1));
}

@Test
@Transactional
public void findAllUsers() {
Iterable<User> users = userJpaRepository.findAll();
for(User user : users) {
System.out.println(user.getName()+"\t"+ user.isLocked());
}
}

}/code] findAllUsers() test is working but insertUser() not working.
 
Puspender Tanwar
Ranch Hand
Posts: 640
2
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
By default, Tests are set to Rollback at the end. So I need to annotate my transactional method with @Rollback(false)
 
You know it is dark times when the trees riot. I think this tiny ad is their leader:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!