- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我使用:NetBeans IDE 6.7.1、GlassFish v2.1、Oracle 10g XE、JAVA 6 SE、JAVA 5 EE。
我对 @ManyToMany 注释有疑问:
@ManyToMany(fetch=FetchType.EAGER)
@JoinTable(name="CUST_RENT_MOVIE", joinColumns={@JoinColumn(name="CUST_ID")}, inverseJoinColumns={@JoinColumn(name="TITLE")})
private Collection<CustRentMovie> rents = new ArrayList<CustRentMovie>();
GlassFish v2.1.1 的部分输出
Exception Description: The @JoinColumns on the annotated element [private java.util.Collection vc.domain.Customer.rents] from the entity class [class vc.domain.Customer] is incomplete. When the source entity class uses a composite primary key, a @JoinColumn must be specified for each join column using the @JoinColumns. Both the name and the referenceColumnName elements must be specified in each such @JoinColumn.
javax.persistence.PersistenceException: Exception [TOPLINK-28018] (Oracle TopLink Essentials - 2.1 (Build b31g-fcs (10/19/2009))): oracle.toplink.essentials.exceptions.EntityManagerSetupException
Exception Description: predeploy for PersistenceUnit [vc_pu] failed.
创建数据库的脚本部分:
CREATE table customer
(
cust_id NUMBER(5),
CONSTRAINT cust_pk PRIMARY KEY (cust_id),
...
)
CREATE TABLE movie
(
title VARCHAR2(50) PRIMARY KEY,
...
)
CREATE TABLE cust_rent_movie
(
title VARCHAR2(50),
cust_id NUMBER(5),
rent_date DATE DEFAULT current_date NOT NULL,
return_date DATE,
CONSTRAINT cust_rent_movie_pk PRIMARY KEY (title, cust_id, rent_date),
CONSTRAINT CustRentMovie_movie_fk FOREIGN KEY (title) REFERENCES movie ON DELETE CASCADE,
CONSTRAINT CustRentMovie_cust_fk FOREIGN KEY (cust_id) REFERENCES customer ON DELETE CASCADE
)
Customer类的代码
@Entity
@Table(name = "customer")
@SequenceGenerator(name="seq", sequenceName="cust_id_seq", allocationSize=1)
public class Customer implements Serializable
{
@Id
@GeneratedValue(strategy=GenerationType.SEQUENCE, generator="seq")
@Column(name="CUST_ID")
private int id;
@ManyToMany(fetch=FetchType.EAGER)
@JoinTable(name="CUST_RENT_MOVIE", joinColumns={@JoinColumn(name="CUST_ID")}, inverseJoinColumns={@JoinColumn(name="TITLE")})
private Collection<CustRentMovie> rents = new ArrayList<CustRentMovie>();
public Collection<CustRentMovie> getRents()
{
return rents;
}
public void setRents(Collection<CustRentMovie> rents)
{
this.rents = rents;
}
...
}
<小时/>
我错误地将 CustRentMovie 类而不是 Movie 作为类型放入集合中,所以我更改了
private Collection<CustRentMovie> rents = new ArrayList<CustRentMovie>();
至
private Collection<Movie> movies = new ArrayList<Movie>();
最佳答案
CustomerRentMovie 的 PK 由三列组成(标题、cust_id、rent_date)。 Toplink 表明您需要在 @JoinColumn 注释中将所有三个指定为连接列(当前您仅指定了 cust_id)。
将注释更改为类似的内容应该可以帮助您解决此错误。
@JoinTable(name = "CUST_RENT_MOVIE", joinColumns = {
@JoinColumn(name = "CUST_ID"),
@JoinColumn(name = "TITLE"),
@JoinColumn(name = "RENT_DATE") }, inverseJoinColumns = { @JoinColumn(name = "TITLE") })
private Collection<CustRentMovie> rents = new ArrayList<CustRentMovie>();
也就是说,帕斯卡的问题是有效的 - 看来您打算建立从客户到电影的关系,而不是从客户到 CUST_RENT_MOVIE 的关系。
关于java - 实体类 [...] 中带注释的元素 [...] 上的 @JoinColumns 不完整,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3462015/
这是简化的代码片段,省略了 IdClass 详细信息。我遇到的问题是表定义是: ClientPersonalityModel ( client_id int not null, personali
我正在编写一个 spring-boot、spring-mvc 应用程序。其中有两个实体:User 和 Task。该任务必须属于用户。我正在尝试使用外键、使用 @OneToMany、@ManyToOne
有关更多上下文,请参阅 my other question。 我想将我的 Employee 实体类加入到 Code 实体类中,但代码 PK 是复合的(DOMAIN、CODE),因为它列出了许多不同的代
我正在尝试使用 @JoinColumn 注释加入一个列,但我的列总是返回 null,我不确定为什么。 @Entity public class Blender implements Serializa
我有实体 User,其中包含实体 Actor 的字段,其中包含具有实体产品的字段。现在我希望数据库中的用户拥有有关产品 id 的信息,该信息使用产品上的 @JoinColum 存储在 Actor 中。
我使用 @JoinColumn 注释进行一对多映射: @JoinColumn(name="domainId",referencedColumnName="domainId")。 但是,表中的外键列名称
@ManyToOne @JoinColumn(name = "someValue" , referencedColumnName = "someOtherValue" ) 如果 2 个表通过 Many
我在尝试为数据库创建一些模型时遇到 JPA 问题。 我有这三个类(我只是将部分代码放在这里): GuideVersionLang @Entity public class GuideVersionLa
我可能只是误解了@JoinColumns 的工作原理,但是当我重用名称属性时出现错误。但是名称属性不映射到数据库列吗?我不应该能够重复使用它吗? 我遇到错误: Repeated column in m
根据 hibernate 文档, hibernate 团队强烈建议不要在没有连接表的情况下使用一对多单向映射。我想知道这是因为性能问题还是背后有任何其他原因。 说如果有一个员工可以有很多电话号码,那么
@ManyToOne(fetch = FetchType.LAZY) @JoinColumn (name = "account_id") private Account account; 工作正常。
我是 HQL 的初学者,并且我陷入了使用 HQL 检索 VesselOperator 记录的困境 我的代码如下所示。 CompanyId.java @Embeddable public class C
抱歉我的问题。实在无法理解我的错误。我在两个类之间有 Hibernate 关系,但是当我运行它时,日志给出了这个错误: org.hibernate.AnnotationException: mappe
我正在研究一个使用 JPA 的项目,我对此还很陌生。我遇到了一个我不太理解的逻辑。我有一个名为 A 的实体,它具有以下字段/列: @Column(name = "COD_UOP_COO") p
我正在将 JPA 与 EclipseLink (2.5.2) 结合使用。 我有以下实体: @Entity @Table(name="Consumer") public class Consumer i
我遇到以下问题:我想简单地加入表“市场”(主)和“电话”,但在使用注释执行此操作时遇到一些问题。 我只是想使用 Comercio.id 作为 Telefone.fk_id 中相应的外键,但它无法识别它
我有以下表格(仅显示最重要的列,A 和 B 不是真实姓名): table A { ... } table B { ... } table METADATA { KEY VALUE
在我的 JPA 类中,我有这个注释和我无法理解的语法 @JoinColumns({ @JoinColumn(name="RES_ID", referencedColumnName="ACCT_
有什么区别: @Entity public class Company { @OneToMany(cascade = CascadeType.ALL , fetch = FetchType.L
我有很多映射实体,它们都是从抽象类 BaseEntityImpl 扩展而来的。 在这个类中,我有 1 个属性 company,注释如下: @ManyToOne(fetch=FetchType.EAGE
我是一名优秀的程序员,十分优秀!