Angularjs 如何使用jpa spring boot js在数据库表中保存数据有两个主键
这是我的实体Angularjs 如何使用jpa spring boot js在数据库表中保存数据有两个主键,angularjs,hibernate,spring-mvc,jpa,spring-boot,Angularjs,Hibernate,Spring Mvc,Jpa,Spring Boot,这是我的实体 我的问题是我不知道为什么我的http请求不起作用 我正在使用ARC应用程序测试requette,这是错误 “地位”:500 “错误”:“内部服务器错误” “异常”:“org.springframework.beans.ConversionNotSupportedException” “信息”:“未能将类型为'java.lang.Long'的属性值转换为属性'fa'所需的类型'com.projet.pfe.entities.AF';嵌套异常为java.lang.IllegalStat
包com.projet.pfe.entities
import java.io.Serializable;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.IdClass;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
@IdClass(ActiviteAF.class)
@Entity
public class ActiviteAF implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@ManyToOne
@JoinColumn(name="idact")
private Activite activite;
@Id
@ManyToOne
@JoinColumn(name="idaf")
private AF fa;
private double montant;
public Activite getActivite() {
return activite;
}
public void setActivite(Activite activite) {
this.activite = activite;
}
public AF getFa() {
return fa;
}
public void setFa(AF fa) {
this.fa = fa;
}
public double getMontant() {
return montant;
}
public void setMontant(double montant) {
this.montant = montant;
}
public ActiviteAF(Activite activite, AF fa, double montant) {
super();
this.activite = activite;
this.fa = fa;
this.montant = montant;
}
public ActiviteAF() {
super();
}
}
这是我的存储库
包com.projet.pfe.DAO
import java.util.Collection;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import com.projet.pfe.entities.ActiviteAF;
public interface ActiviteAFRepository extends JpaRepository<ActiviteAF,Long> {
@Query("select af from ActiviteAF af where af.activite.idActivite like :x")
public Collection<ActiviteAF> activitebyid(@Param("x") Long id);
}
我找到了一个解决方案,只需制作一个单独的.Id并将其他的更改为一个简单的注释(forign keys),这个解决方案可以工作,但在添加新对象时需要测试(activite,af)。我找到了一个解决方案,只需制作一个单独的.Id并将其他的更改为一个简单的注释(forign keys),这个解决方案可以工作,但需要测试(activite,af)在添加新对象的情况下
import com.projet.pfe.DAO.AFRepository;
import java.util.Collection;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import com.projet.pfe.DAO.ActiviteAFRepository;
import com.projet.pfe.DAO.ActiviteRepository;
import com.projet.pfe.entities.AF;
import com.projet.pfe.entities.Activite;
import com.projet.pfe.entities.ActiviteAF;
import org.springframework.web.bind.annotation.PathVariable;
@RestController
public class ActAFRestService {
@Autowired
private ActiviteAFRepository actafmet;
@Autowired
private ActiviteRepository actr;
@Autowired
private AFRepository afr;
@RequestMapping(value="/saveactaf/{idact}/{idaf}/{montant}",method=RequestMethod.POST)
public ActiviteAF save(@PathVariable(name="idact")long idact,@PathVariable(name="idaf")long idaf,@PathVariable(name="montant")double montant){
Activite a = new Activite();
AF af = new AF();
a = actr.findOne(idact);
af = afr.findOne(idaf);
ActiviteAF aaf = new ActiviteAF(a,af,montant);
return actafmet.save(aaf);
}
}