0

Like I have an ArrayList, Then I call my repo from service, somewhat like

userRepository.insertUsers(userArrayList);

and here i have my repository

@Repository
public interface UserRepository extends JpaRepository<User, Long> {

@Transactional
@Modifying()
@Query("INSERT INTO usermaster ..........")
    public int insertUsers(@Param("userArrayList") List<User> userArrayList);

}

all I need is a query to bulk insert this ArrayList above, I couldn't find an answer for this. Thanks in advance.

2
  • 1
    have you tried with the default method save? like this: userRepository.save(userArrayList); Commented Jul 25, 2017 at 9:31
  • You don't need a @Repository annotation when you implement on of Spring Datas repository interfaces. Commented Jan 30, 2018 at 5:54

1 Answer 1

3

You do not need custom method, JpaRepository has save method which accepts list of your entity, this will be enough

userRepository.save(userArrayList);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.