目前我有两个表 - 产品和统计。和两个java enitities(Product,Statistics)
它们之间的映射是1:1。
我想摆脱一个实体(Statitics),因为从这个实体我只需要一个名为" magicValue"的列。
有没有办法如何只使用一个实体 - 产品,其中包含magicValue?
(不需要统计课程?)
我在考虑使用OneToOne映射或嵌入式类型,但是对于所有这些可能性,需要统计java类
如果我的问题不合理,请根据您的知识给我写一份最佳解决方案。
从表产品我需要所有列 从表格统计信息我只需要一列( MAGIC_VALUE )
Sql表:
CREATE TABLE PRODUCT
(
"PRODUCT_ID" NUMBER(20,0),
"NAME" VARCHAR2(30 BYTE),
PRIMARY KEY (`PRODUCT_ID`)
);
CREATE TABLE STATISTICS
(
"STATISTICS_ID" NUMBER(20,0) PRIMARY KEY,
"PRODUCT_ID_FK" NUMBER(20,0),
"MAGIC_VALUE" VARCHAR2(30 BYTE),
"OTHER_USELESS_COLUMN" VARCHAR2(30 BYTE),
...
PRIMARY KEY (`STATISTICS_ID`)
FOREIGN KEY (`PRODUCT_ID_FK`) REFERENCES PRODUCT(PRODUCT_ID)
);
当前的Java类如下所示:
@Entity
@Table(name="PRODUCT")
class Product {
@Id
@Column(name = "PRODUCT_ID")
protected Integer productId;
@Column(name = "NAME")
protected String name;
@OneToOne(cascade = CascadeType.ALL)
@PrimaryKeyJoinColumn
protected Statistics stat;
}
这是统计java类
我只需要一列(magicValue)
@Entity
@Table(name="STATISTICS")
class Statistics {
@Id
@Column(name = "STATISTICS_ID")
protected Integer statisticsId;
@OneToOne(mappedBy = "statistics")
protected Product product;
@Column(name = "MAGIC_VALUE")
protected String magicValue; // <-- only this is needed
@Column(name = "OTHER_USELESS_COLUMN")
protected String uselessColumn;
...
}
仅更改Product java类:
@Entity
@Table(name="PRODUCT")
class Product {
@Id
@Column(name = "PRODUCT_ID")
protected Integer productId;
@Column(name = "NAME")
protected String name;
@someHowMap to sql table Statistics, but in Product have direct magicValue value
protected String magicValue;
}
谢谢
答案 0 :(得分:1)
STATISTICS
该公式将起作用,它使用SQL而不是HQL,因此在Java类中不需要val firehoseSource = Source.actorPublisher[FirehoseActor.RawTweet](
FirehoseActor.props(
auth = ...
)
)
val ref = Flow[FirehoseActor.RawTweet]
.map(r => ResponseParser.parseTweet(r.payload))
.map { t => println("Received: " + t); t }
.to(Sink.onComplete({
case Success(_) => logger.info("Stream completed")
case Failure(x) => logger.error(s"Stream failed: ${x.getMessage}")
}))
.runWith(firehoseSource)
的实体。