【发布时间】:2018-12-01 10:30:17
【问题描述】:
我使用 spring Initializr 创建了一个 Spring Boot 项目,选择了 Web 和 JPA 依赖项。
我可以进行休眠调用,例如save() - 但是 JPA 方法(例如 persist()、merge())不可用。
//JpRepository.java
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
@Repository
public interface JpRepository extends JpaRepository<Jp, Long> {
}
//JpServiceImpl
import com.jp.jp.db.JpRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.persistence.EntityManager;
import javax.persistence.EntityTransaction;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;
import java.util.*;
@Service
public class JpServiceImpl {
@Autowired
private JpRepository jpRepository;
@Transactional
public void readJp() {
jpRepository.save(jp); // is available
jpRepository.merge(jp); // this method is not available
}
}
}
【问题讨论】:
标签: spring-boot jpa spring-data-jpa