Win a copy of JDBC Workbook this week in the JDBC and Relational Databases forum
or A Day in Code in the A Day in Code 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
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

Spring Data JPA not persisting entity

 
Ranch Hand
Posts: 649
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: 649
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: 649
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)
 
What do you have in that there bucket? It wouldn't be a tiny ad by any chance ...
Devious Experiments for a Truly Passive Greenhouse!
https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
    Bookmark Topic Watch Topic
  • New Topic