- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用 Hibernate 编写 JEE Web 应用程序。我正在使用注释在 beans 中进行映射。
我展示
尽管我对论坛和其他网站进行了研究,但我无法使我的主键与外键组合,如上图所示。
我刚刚设法将我的“id-command”键放入 FK,但我希望她来编写 PK。
预先感谢您的帮助。
祝你有美好的一天。
最佳答案
感谢您的回答。
当应用程序首次启动时,数据库没有表。它们是由 Hibernate 创建的。
我给你我的代码(我给你的代码中没有 getter 和 setter):BonLivraison 类(该类代码末尾只是一个尝试)
包 sii.dsi.beans;
import java.io.Serializable;
import java.util.Date;
import javax.persistence.*;
@SuppressWarnings("serial")
@Entity
@Table
public class BonLivraison implements Serializable{
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
private int id_bon_livraison;
@Column(nullable=false, length=255, unique=false)
private String numero_bon_livraison;
@Column(nullable=false, unique=false)
private double montant_bon_livraison;
@Column(nullable=false, unique=false)
private Date date_bon_livraison;
@Column(nullable=false, unique=false)
private Date date_depot_facture;
@OneToOne
@JoinColumn(name="id_commande")
private PosteLigne poste_ligne_id_commande;
@OneToOne
@JoinColumn(name="id_posteligne")
private PosteLigne poste_ligne_id;
// Getters and Setters
}
指挥官级:
package sii.dsi.beans;
import java.io.Serializable;
import javax.persistence.*;
import sii.dsi.beans.Affaire;
@SuppressWarnings("serial")
@Entity
@Table
public class Commande implements Serializable{
@Column
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
private int id_commande;
@Column(nullable=false, length=255, unique=false)
private String numero_commande;
@Column(nullable=false, length=255, unique=false)
private String numero_bc;
@OneToOne
private Affaire affaire;
}
类PosteLigne:
package sii.dsi.beans;
import java.io.Serializable;
import javax.persistence.*;
@SuppressWarnings("serial")
@Entity
@Table
public class PosteLigne implements Serializable{
@EmbeddedId
private PosteLignePK poste_ligne_pk;
@Id
private int id_poste_ligne;
@Column(nullable=false, unique=false)
private double montant_poste_ligne;
@Column(nullable=false, unique=false)
private boolean clos;
@Column(nullable=false, unique=false)
private int numero_ligne;
}
类PosteLignePK:
package sii.dsi.beans;
import java.io.Serializable;
import javax.persistence.*;
@SuppressWarnings("serial")
@Embeddable
public class PosteLignePK implements Serializable{
private int id_poste_ligne;
@OneToOne
@JoinColumn(name="id_commande")
private Commande commande;
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + id_poste_ligne;
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
PosteLignePK other = (PosteLignePK) obj;
if (id_poste_ligne != other.id_poste_ligne)
return false;
return true;
}
}
错误消息:
A Foreign key refering sii.dsi.beans.PosteLigne from sii.dsi.beans.BonLivraison has the wrong number of column. should be 2
我认为问题出在 BonLivraison 类(class)的末尾。
感谢您的帮助
关于java - 主键由一个外键组成,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52180504/
编辑:我将问题重新表述为更简单且不那么特定领域的问题: 在下面的代码中,我想实现 mplus 函数,该函数结合了受特定字段存在约束的两个函数。结果函数应受两个字段的存在的约束。 谢谢 ! import
我的代码有什么问题?提前致谢! 我正在尝试为我的 docker 容器设置一个虚拟主机。在本地主机上:8000 完美运行,但是当我尝试通过 http://borgesmelo.local/访问时,出现错
这个问题在这里已经有了答案: CSS technique for a horizontal line with words in the middle (34 个答案) 关闭 2 年前。 首先,这是
我是 React Js 的新手,并尝试了解如何通过 ajax 对从不同来源获得的数据进行组合(如下所述: Reactjs - loadResourcesFromServer - combine two
我一直在关注 this tutorial在 docker 服务和 swarms 上。但是我在不同 docker 容器之间的网络连接上遇到了一些问题。 以下是我的 docker-compose.yml
我正在尝试创建一个相对简单的设置来开发和测试 npm 包。事实上,一个问题是,在将代码卷安装到容器后,它会替换 node_modules。 我尝试了很多通常合乎逻辑的东西,主要是为了将 node_mo
我有四种类型A、B、C和D,初始值x Future[Option[A]] 和三个函数:f1: A => Option[B] , f2: B => Future[Option[C]] 和 f3: C =
我有一个包含单词的语料库。我想对他们做一个分析。我接受它们是土耳其字符,但其中一些不是。所以我想检查一个词是否不包含土耳其字符或数字。我的意思是: hey4 valid 33 vali
这是我正在为 Java 入门课解决的学校问题。作业是编写一个程序,生成一个由随机生成的二进制数组成的 8 x 8 矩阵,并让程序检查哪些列(如果有)全为 0,以及主对角线和次对角线是否也由零组成。主对
我正在尝试编写一个由任意数量的 lambda 函数组成的函数。 我有两个简单的 lambda 函数。 f = lambda x: x + 1 g = lambda x: x**2 我对组合函数的尝试是
我在这里学习 Docker Compose 教程 https://docs.docker.com/get-started/part5/#recap-optional version: "3" serv
我正处于要为应用程序编写 androidTests 的状态。 阅读 Testing Compose 的文档,我创建了一个文件并编写了一个简单的测试来检查进度: ExamineTest.kt: clas
我最近刚跨过木偶继承。围绕它的几个问题: 使用p继承是一种好习惯吗?一些经验丰富的木偶同事告诉我,木偶的继承不是很好,我不太相信。 来自OO世界,我真的很想了解木偶继承的原理,以及覆盖的原理。 最佳答
我正在尝试使用 docker-compose 创建一个基本网页 这是我的 yml 文件 identidock: build: . ports: - "5000:5000" envir
我们有docker-compose.yml,其中包含Kafka,zookeeper和schema registry的配置 当我们启动docker compose时,出现以下错误 docker-comp
我在玩 Haskell 的类型时无意中发现了 length 。总和 有效。是否有一些语义应该允许它工作,或者这仅仅是类型定义的一个缺点?我在下面编写了每个类型定义。 length :: Foldabl
如何防止缩小仅包含 JFormattedTextFields 的 JPanel。 JFormattedTextField textF1; JFormattedTextField textF2;
我尝试更 retrofit 载我的 Docker 卷的用户,但执行此操作的是“root”用户,而不是“安全用户”。知道如果我在 Dockerfile 中执行“chown -R/var/www”,这将不
我正在尝试将 scalaz 的 ioeffect IO[E,A] monad 用于一段非常有效的代码。 我试图用 IO[E,A] 在高层次上重写的代码需要一些关于存储在云中的文件的元数据。代码试图:
这个问题已经有答案了: What special characters must be escaped in regular expressions? (13 个回答) 已关闭 5 年前。 java中
我是一名优秀的程序员,十分优秀!