Java JPA使用其他列在哪里从其他表中选择列

问题描述

我有两个表:

create table table_binding (id bigint not null,description varchar(255),primary key (id));

create table table2 (id bigint not null,value clob,type varchar(255));

例如,表格已填充下一个值:

table_binding:

|---------------------|------------------|
|          ID         |    Description   |
|---------------------|------------------|
|          1          |     Some Desc    |
|---------------------|------------------|
|          2          |    Other Desc    |
|---------------------|------------------|

表2:

|---------------------|------------------|------------------|
|          ID         |       value      |       type       |
|---------------------|------------------|------------------|
|          1          |      VALUE_A     |       TYPE1      | 
|---------------------|------------------|------------------|
|          1          |      VALUE_B     |       TYPE2      | 
|---------------------|------------------|------------------|
|          2          |      VALUE_C     |       TYPE1      | 
|---------------------|------------------|------------------|
|          2          |      VALUE_D     |       TYPE2      | 
|---------------------|------------------|------------------|

我只有一个实体

@Entity(name = "table_binding")
@Data
public class myBinding(){

    @Id
    @GeneratedValue(strategy= GenerationType.SEQUENCE)
    Long id; 
    private String description;
    @Clob
    private String value1;
    @Clob
    private String value2;

}

我如何修改实体类代码以使value1和value2与下一个sql查询的返回值相同: 值1:

select value.t2 from table2 t2,table_binding t1 where t2.type="TYPE1" and t2.id=t1.id and t1.id=?

value2:

select value.t2 from table2 t2,table_binding t1 where t2.type="TYPE2" and t2.id=t1.id and t1.id=?

我的意思是id = 1的myBinding实体将是: id = 1; descripton =“ Some Desc”; valu1 =“ VALUE_A”; value2 =“ VALUE_B”

我知道@SecondaryTable和@Column批注,但是它们不允许实现

where t2.type="TYPE1"

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)