Возникла проблема при сохранении объекта в базу данных на RDS
.Эта проблема за пределами моего понимания, так как save
работает нормально, когда я запускаю приложение на моей машине.то есть из Intellij (не знаю, стоит ли упоминать Intellij или нет).
Вот класс сущностей
@Entity
@Table(name = "spr_material")
public class SprMaterial {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "id")
private Integer id;
@CreationTimestamp
@Column(name = "created_at", nullable = false, updatable = false)
public Timestamp createdAt;
@Column(name = "service_name")
public String serviceName;
@UpdateTimestamp
@Column(name = "updated_at")
public Timestamp updatedAt;
@Column(name = "isDeleted")
private Boolean isDeleted;
@Transient
private int serialNo;
@ManyToOne()
@JoinColumn(name = "dep_id", nullable = true)
private Department department;
@ManyToOne()
@JoinColumn(name = "item_code", nullable = true)
private StockRawMaterial rawMaterial;
// removing get/set methods
@Override
public String toString() {
return "ID: "+this.id+ " Created At: "+this.createdAt+ " Service Name: "+this.serviceName+ " Deleted: "+this.isDeleted
+ " Department Id: "+this.department.getDepId()+ " Raw Material Id: "+this.rawMaterial.getRawMaterialId();
}
}
Вот фрагмент кода, которыйсохраняет данные в базу данных
В Controller
классе
@PostMapping("/spr/save")
public String sprMaterial_save(@ModelAttribute("sprForm") SprForm sprForm, RedirectAttributes redirectAttributes) {
SprMaterial sprMaterial = new SprMaterial();
sprMaterial.setId(sprMaterialService.getMaxId());
sprMaterial.setServiceName(sprForm.getServiceName());
sprMaterial.setRawMaterial(rawMaterialService.findById(sprForm.getItemCode()));
sprMaterial.setDepartment(departmentService.findByDeptId(sprForm.getDepartmentId()));
//sprMaterial.setDeleted(false);
logger.info("TESTING");
SprMaterial saved = sprMaterialService.save(sprMaterial);
if(saved == null){
System.out.println("Could not saved object");
}else {
System.out.println("Saved Successful");
}
redirectAttributes.addFlashAttribute("addedSuccess", "success");
return "redirect:/spr/accounts";
}
В классе обслуживания
@Override
public SprMaterial save(SprMaterial sprMaterial) {
logger.info("SAVING SPR MATERIAL: "+sprMaterial.toString());
SprMaterial rm = sprRepository.save(sprMaterial);
logger.info("after saving: "+rm.toString());
return rm;
}
ОБНОВЛЕНИЕ: Я использую метод jpa по умолчанию save
.Вот класс репозитория.
public interface SprRepository extends JpaRepository<SprMaterial, Integer> {
@Query(value = "SELECT spr.* FROM spr_material spr JOIN department d ON d.dep_id = spr.dep_id WHERE d.name LIKE ?1 AND spr.isDeleted = FALSE ORDER BY ?#{#pageable}",
countQuery = "SELECT spr.* FROM spr_material spr JOIN department d ON d.dep_id = spr.dep_id WHERE d.name LIKE ?1 AND spr.isDeleted = FALSE ORDER BY ?#{#pageable}", nativeQuery = true)
Page<SprMaterial> findSprMaterialById(String name, Pageable pageable);
@Modifying
@Transactional
@Query(value = "UPDATE spr_material spr SET spr.`isDeleted` = 1 WHERE spr.`id` = ?1", nativeQuery = true)
void deleteSprMaterial(Integer sprMaterialId);
SprMaterial findById(Integer sprMaterialId);
@Query(value = "SELECT MAX(spr.`id`) + 1 FROM spr_material spr",nativeQuery = true)
Integer getMaxId();
@Query(value = "select * from spr_material spr where spr.`dep_id`=?1",nativeQuery = true)
SprMaterial findByDepId(Integer deptId);
}
На tomcat catalina.out
я получаю следующие журналы и получаю страницу с 504
error
14-Jun-2019 11:58:45.363 INFO [http-nio-80-exec-34] com.qsa.account.web.SprMaterialController.sprMaterial_save TESTING
14-Jun-2019 11:58:45.374 INFO [http-nio-80-exec-34] com.qsa.account.service.sprMaterial.SprMaterialServiceImpl.save SAVING SPR MATERIAL: ID: 2 Created At: null Service Name: Vilcor Disc Repair and Maintenance Deleted: false Department Id: 7 Raw Material Id: 5350
Hibernate: select sprmateria0_.id as id1_53_0_, sprmateria0_.created_at as created_2_53_0_, sprmateria0_.dep_id as dep_id6_53_0_, sprmateria0_.isDeleted as isDelete3_53_0_, sprmateria0_.item_code as item_cod7_53_0_, sprmateria0_.service_name as service_4_53_0_, sprmateria0_.updated_at as updated_5_53_0_ from spr_material sprmateria0_ where sprmateria0_.id=?
11:58:45,384 TRACE BasicBinder:81 - binding parameter [1] as [INTEGER] - [2]
11:58:45,413 WARN PageNotFound:215 - Request method 'POST' not supported