- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有以下具有单表继承策略的实体。
@Entity
@Inheritance
@DiscriminatorColumn(name="type")
public abstract class Vehicle extends com.avaje.ebean.Model {
@Id
public Long id;
public String name;
public String description;
}
@Entity
@DiscriminatorValue("b")
public class Bus extends Vehicle {
public String field1;
}
@Entity
@DiscriminatorValue("c")
public class Car extends Vehicle {
public String field2;
}
我的 UI 中有一个表,该表应显示包含车辆字段列的行。我想进行高级搜索,用户可以按类型过滤车辆列表。
我的问题是如何创建查询以按车辆类型过滤列表。像这样:
List<Vehicle> list = com.avaje.ebean.Ebean.find(Vehicle.class)
.where().eq("type", "c").findList();
如果我插入一个已经讨论过的具有以下定义的字段 here ,我会收到一条错误消息“注入(inject)构造函数时出错,java.lang.IllegalStateException:在类型类模型的 [id,名称,描述] 中找不到属性 theType。车辆”
@Column(name = "type", insertable = false, updatable = false)
public String theType;
如果我将它设置为@Transient,我将无法在查询中使用它。
最佳答案
您可以使用@Formula 注释,如ebean docs 中所述。 .
@Transient
@Formula(select = "type")
public String theType;
当然要注意:
As the field is also Transient it is not included by default in queries - it needs to be explicitly included.
关于java - 使用单表继承时如何在Ebean查询中使用鉴别器值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45613257/
我习惯于创建基本查询,所以我被困在一个相当复杂的查询上。 Order Number Order Line Package Part Number Size Cost
我想创建类似 tinder/whatsapp 的消息。 我有一个名为“消息”的表,我想显示用户之间的所有对话(最后一条消息) 表结构: message_id | user_id | recipient
我有一个如下所示的表,我想获取每个 loc_id 的最新 insp_date 的 ID (insp_id)。 create table insp ( insp_id int (10),
我正在尝试解决以下问题,如 this table, sql statement and comments 所示 表列:id,版本,idx_on; PK 是“id”列 所以,我从子查询中得到一组元组{i
我正在尝试使用 HQL 创建简单的选择查询。有一个将在查询中使用的实体。它看起来像下面这样: @Entity @Table(name = "my_table") public class MyTabl
我有一个带有单表映射的层次结构。我使用 HSQLDB 进行自动生成 DDL 功能的测试。层次结构中的子类之一具有标量长字段。 我无法保留其他子类的对象,因为第一个类的数据库行字段为空。 Hiberna
我有不同的客户及其信息。所有客户都有相同的信息。一个客户端就是一张表,每个客户端都具有与其他客户端相同的列。 我的问题是,什么更有效或什么更好,或者哪种是实现此目的的最佳方法? 只有一张表包含所有客户
我目前正在开发一个系统,允许使用关键字标记文档并具有以下形式的表格: CREATE TABLE `KeywordsToDocuments` ( `keywordID` int NOT NULL
我有一个成员表:成员(id, name, gender, head_id) 我想要的是建立以户主(家庭成员)为基础的家庭关系。就像这样:一个成员属于一个家庭(由成员定义) 也许我可以将其拆分为 2 个
我有下表: id | billingno | location ------------------------- 1 | 9999999 | Toronto 2 | 9999999 |
我被要求为我们的应用程序考虑一个数据库。大约有7种不同的数据需要存储。一种是标识数据,其中可能包含唯一的序列号、时间、位置。所有其他 6 个数据集(4 个二进制原始数据,2 个文本数据)必须由标识数据
我在 stackoverflow 上搜索过类似的问题,但我不明白如何让它工作,我想做什么... 所以,我想从数据库中获取最近 7 天的交易并获取总销售额,如果某天没有数据,还包括空行。 我目前拥有的:
想象一下以下类别:酒吧、吃饭的地方、商店等...... 每一个分类都会有一些共同的字段,比如 id, name, address and geolocation (Lat and Lng positi
我一直在搜索整个谷歌 - 我可能只是愚蠢地理解答案。 我在 mysql 中有一个表 - 问题。 +-------------+---------------+------+-----+--------
我是 SQL 和 mySQL 的新手,我自学并尝试编写一个查询,向我显示 ID 列中匹配的 ID 的计数为 3 或更少的所有行。 例如: Id timestamp Num
我目前正在处理一个查询,该查询根据书的属性从表中搜索书籍。该表包含超过 5000 万行,结构如下: ----------------------- | book_id | attr_id | --
我是一名优秀的程序员,十分优秀!