• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

Spring Data JPA not persisting entity

 
Ranch Hand
Posts: 658
2
Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 658
2
Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 658
2
Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic