Hibernate-尝试执行插入时的无键键



当我执行插入时,传统的外键(iDmot参考mot)为无效,在我的正面发送正确的外键。我最终遇到了此错误:非零件属性引用null或瞬态值:com.virtual.expertise.mydico.model.model.traduction.mot

我想我在模型中做错了什么,但仍然不知道。

这是传统模型:

      @Id
            @Column(name = "id")
            @GeneratedValue(strategy = GenerationType.IDENTITY)
            private Long id;
            @Column(name = "langue")
            private String langue;
            @Column(name = "traduction")
            private String traduction;
            @JsonBackReference(value = "mot-traduction")
            @ManyToOne(fetch = FetchType.EAGER)
            @JoinColumn(name = "idMot", nullable = false, insertable = true, 

updatable = false)
        private Mot mot;
        @CreationTimestamp
        @Column(name = "dateCreation")
        private Date dateCreation;

这是MOT模型:

@Id
    @Column(name = "id")
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;
    @Column(name = "libelle")
    private String libelle;
    @JsonBackReference(value = "user-mot")
    @ManyToOne(fetch = FetchType.EAGER)
    @JoinColumn(name = "idUser", nullable = false, insertable = true, updatable = false)
    private User user;
    /** les traductions. */
    @JsonManagedReference(value = "mot-traduction")
    @OneToMany(mappedBy = "mot", cascade = CascadeType.ALL, fetch = FetchType.EAGER)
    private Set<Traduction> traductions;
    @CreationTimestamp
    @Column(name = "dateCreation")
    private Date dateCreation;

这是传统表:

DROP TABLE IF EXISTS `traduction`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `traduction` (
  `id` bigint(20) NOT NULL AUTO_INCREMENT,
  `langue` varchar(100) DEFAULT NULL,
  `traduction` varchar(100) DEFAULT NULL,
  `idMot` bigint(20) DEFAULT NULL,
  `dateCreation` datetime DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `idMot_idx` (`idMot`),
  CONSTRAINT `idMot` FOREIGN KEY (`idMot`) REFERENCES `mot` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=latin1;
/*!40101 SET character_set_client = @saved_cs_client */;

这是我的Web服务:(在Traduction IDMOT中以null为null)

@POST
    @Path("/create")
    public Traduction createTraduction(Traduction traduction) throws Exception {
        return FacadeBackOffice.getInstance().getTraductionService().createTraduction(traduction);
    }

某人可以有解决方案吗?

使用级联键入您的许多映射中的所有级别。

 @Id
            @Column(name = "id")
            @GeneratedValue(strategy = GenerationType.IDENTITY)
            private Long id;
            @Column(name = "langue")
            private String langue;
            @Column(name = "traduction")
            private String traduction;
            @JsonBackReference(value = "mot-traduction")
            @ManyToOne(fetch = FetchType.EAGER, cascade=CascadeType.ALL)
            @JoinColumn(name = "idMot", nullable = false, insertable = true, 

updatable = false)
        private Mot mot;
        @CreationTimestamp
        @Column(name = "dateCreation")
        private Date dateCreation;

相关内容

  • 没有找到相关文章

最新更新