Java 在spring数据中使用hibernate存储对象列表
我需要在spring数据中使用hibernate在db中存储一个对象列表。基本上,我需要将列表存储在与数据库的单个交互中 为此,我尝试如下:Java 在spring数据中使用hibernate存储对象列表,java,spring,hibernate,Java,Spring,Hibernate,我需要在spring数据中使用hibernate在db中存储一个对象列表。基本上,我需要将列表存储在与数据库的单个交互中 为此,我尝试如下: //a part of my code: if(vacationAirTravellerLegInfoList.size() != 0) { customVacationAirTravellerLegInfoRepository.save(vacationAirTravellerLegInfoList); } 对于上述部分,
//a part of my code:
if(vacationAirTravellerLegInfoList.size() != 0) {
customVacationAirTravellerLegInfoRepository.save(vacationAirTravellerLegInfoList);
}
对于上述部分,“customVacationAirTravellerLegInfoRepository”是我试图实现的自定义存储库的对象,具体如下:
@Repository
public interface CustomVacationAirTravellerLegInfoRepository extends VacationAirTravellerLegInfoRepository, CrudRepository<VacationAirTravellerLegInfo, Integer> {
List<VacationAirTravellerLegInfo> save(List<VacationAirTravellerLegInfo> airTravellerLegInfoList);
}
任何人请建议或纠正我。您可能需要转换列表元素
VacationAirTravellerLegInfo vacationAirTravellerLegInfo = (VacationAirTravellerLegInfo) airTravellerLegInfoList.get(i);
事实上,我甚至无法在save方法中获得控制权。我根据给定的异常进行了假设,该异常表示“spring数据试图在ArrayList中找到“id”属性。”
{
"timestamp": 1529303873662,
"status": 500,
"error": "Internal Server Error",
"exception": "org.springframework.beans.NotReadablePropertyException",
"message": "Invalid property 'id' of bean class [java.util.ArrayList]: Could not find field for property during fallback access!",
"path": "/api/server/vacation/save"
}
VacationAirTravellerLegInfo vacationAirTravellerLegInfo = (VacationAirTravellerLegInfo) airTravellerLegInfoList.get(i);