- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我最近遇到了一个带有嵌入式 id 的类的问题。每当我想要更新数据库中的现有条目时,都会收到错误“java.lang.RuntimeException:在类中找不到@javax.persistence.Id字段
”。仅当我在已经是令人兴奋的数据库条目的对象上使用 update()
或 save()
时,才会出现此错误。使用 save()
插入新条目可以正常工作,使用 delete()
删除现有条目也可以。
其他人在 Play Framework Google Group 中发布了有关此问题的问题,但遗憾的是从未得到答复。所以我想我应该尝试在这里寻求帮助。
这是我的代码的基本外观:
@Entity
@Table(name = "files_location")
public class FilesLocation extends Model {
@EmbeddedId
public FilesLocationPK ids;
@Column(name="status")
public Character status;
@ManyToOne
@MapsId("fileId")
@JoinColumn(name = "file_id", referencedColumnName = "id", insertable = false, updatable = false)
public File file;
@ManyToOne
@MapsId("locationId")
@JoinColumn(name = "location_id", referencedColumnName = "id", insertable = false, updatable = false)
public Location location;
}
@Embeddable
public class FilesLocationPK {
@Column(name="file_id")
public Integer fileId;
@Column(name="location_id")
public Integer locationId;
...
}
错误看起来像这样:
java.lang.RuntimeException: No @javax.persistence.Id field found in class [class models.FilesLocation]
at play.db.ebean.Model._idAccessors(Model.java:39)
at play.db.ebean.Model._getId(Model.java:52)
at play.db.ebean.Model.hashCode(Model.java:183)
at java.lang.Object.toString(Object.java:219)
at java.text.MessageFormat.subformat(Unknown Source)
at java.text.MessageFormat.format(Unknown Source)
at java.text.Format.format(Unknown Source)
at java.text.MessageFormat.format(Unknown Source)
at com.avaje.ebeaninternal.server.core.Message.msg(Message.java:39)
...
最佳答案
您需要在 PK 类中的关键列上使用 @Id 注释。
Ebean 也希望找到一个序列来生成这些序列。
关于java - Play 2.0.4 更新使用 @EmbeddedId 的类时出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13765775/
我有一个表,其中包含一个序列和两个外键的复合主键 我能够持久化我的实体类,但它没有按照顺序生成。由一个序列和两个外键组成的复合主键的表,maven中的hbm2java给出了以下实体 这是主要实体 pa
我有一个 hibernate 映射问题。我有以下两个数据库表(我不允许更改数据库): LOCATIONS { ID, -- PK NAME } LOCATION_GROUPS { L
我知道Hibernate中@EmbeddedId注解的复合主键至少由嵌入主键对象的所有对象变量的组合组成。 但是主键对象本身的引用是否也属于复合主键,因此它是由嵌入主键对象的引用值和对象变量构建的?
我对我的表格/实体有疑问。 我的 SQL 表如下所示: 表 1: IdTable1(pk) 属性... 表 2: IdTable2(pk) 属性... 表3: IdTable1(pk) IdTable
这是我的问题 IdComposite 类: @Embeddable public class IdComposite implements Serializable{ @Column(name =
我正在尝试使用引用另一个表的复合主键。我看到了很多主题,但没有答案适用于我的情况。 在我的数据库中,列是由未添加 owner_id 的外键正确创建的。因此,即使员工不存在,我也可以添加新记录。我使用
我收到了一个 Eclipse 错误:@EmbeddedId . 这是实体: @Entity @Table(name = "PERSON") public class Person implements
所以我这里有一个看起来像这样的图表, 可以在此 Answer Here 中找到. +---------------+ +-------------------+ | PRODUCTS
当我尝试从 JPA 存储库获取实体列表时,总是会遇到这样的异常 org.springframework.orm.jpa.JpaSystemException: No default construct
我正在尝试在一个类之间创建一对一的关系,我们将其称为“第一”,另一个类将其称为“第二”。 如果 Second 类使用 @EmbeddedId 作为其主键,它不会允许我这样做,我该如何解决这个问题? 基
我正在使用 hibernate,并且我已经使用 hibernate 在 java 端创建了实体。我的一个数据库表有多个列作为主键,hibernate 使用 @EmbeddedId 来处理这个问题。 我
我有一个主类和一个辅助类,用于存储保存时的错误。错误可以有多种类型,主键是错误的主要类别和类型。这是我的类的映射: 我的初级类(class): @Entity @Table(name = "foo")
我有一个具有复合主键的@Entity。因此,我创建了一个包含 PK 字段的 @EmbeddedId。 问题:是直接通过id.*访问这些字段更好,还是应该在父类中创建getter/setter? 例子:
我有一个包含三个字段 A、B、C 的 @Entity,其中 A 和 B 充当复合主键。我创建了一个包含 A 和 B 的 @EmbeddedId 类。为了减轻定义 getter 和 setter 的负担
在使用 hibernate 和 JPA 的 Spring MVC 应用程序中,我尝试为其基础数据表具有两列主键的实体设置映射。 如何更改下面的代码以使其正常工作? 我创建了一个名为 conceptPK
我有我的实体: @Entity @Table(name="performances") @AssociationOverrides({ @AssociationOverride(name="i
我有点麻烦。我正在使用 JPA Criteria 进行动态选择(使用标准作为 where 子句具有可选变量...)但我的实体之一有一个 EmbeddedId ,其中包含其中的用户列并且需要检查用户 I
我想使用条件进行以下查询。我有一个定义了 EmbeddedId 的 Entity: @Entity @Table(name="TB_INTERFASES") public class Inter
我的 @MapsId 注释和 @EmbeddedId 存在问题。在 Hibernate 中运行代码时,我得到: Caused by: org.hibernate.PropertyAccessExcep
我有以下实体: @Entity(name = "game_users") public class GameUser { private GameUsersPK primaryKey;
我是一名优秀的程序员,十分优秀!