FIELD_5是TABLE_1中的主键,而不是TABLE_2中的外键。显示未找到FIELD_5列。
使用Hibernate XML进行映射。 FIELD_5映射到XML
造成:java.sql.SQLException: Column 'FIELD_5'
未找到。
select
inv.Field_ID,c.FIELD_7 as FIELD_7,s.FIELD_3,sum(inv.FIELD_4) as FIELD_4
from
(SELECT
m.Field_ID, t.FIELD_1,t.FIELD_2, t.AMOUNT as FIELD_4
FROM
TABLE_1 m
INNER JOIN TABLE_2 t ON m.FIELD_5 = t.FIELD_5
Where
m.FIELD_6 = 'PURCHASE' AND m.Field_ID=2
and m.FIELD_7 = 'S' and t.TFIELD_8 != 'F'
AND t.CREATED_DATE BETWEEN '2016-04-01 00:00:00' AND '2017-03-31 00:00:00'
) as inv
INNER JOIN
(select distinct FIELD_3,FIELD_2 from TABLE_4 ) as s
ON inv.FIELD_2=s.FIELD_2
INNER JOIN TABLE_3 c on inv.Field_ID=c.Field_ID
where s.FIELD_3 in (400019,400004,400012)
group by inv.Field_ID,s.FIELD_3;
我在TABLE_2实体中添加了 @ManyToOne @JoinColumn(名称= “FIELD_5”) private String field5;
如何使用此SQL查询生成SQL查询
表格方案
CREATE TABLE `TABLE_2` (
`FIELD_5` varchar(30) NOT NULL,
`FIELD_1` bigint(20) NOT NULL,
`FIELD_2` bigint(20) NOT NULL,
`FIELD_6` varchar(10) DEFAULT NULL,
`FIELD_8` varchar(10) DEFAULT NULL,
`CREATED_BY` varchar(255) NOT NULL,
`CREATED_DATE` datetime NOT NULL,
`MODIFIED_BY` varchar(255) DEFAULT NULL,
`MODIFIED_DATE` datetime DEFAULT NULL,
PRIMARY KEY (`ORDER_ID`,`SCHEME_REF_ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8
CREATE TABLE `TABLE_1` (
`FIELD_5` varchar(30) NOT NULL,
`Field_ID` bigint(20) NOT NULL,
`FIELD_6` varchar(40) NOT NULL,
`FIELD_7` varchar(10) DEFAULT NULL,
`CREATED_BY` varchar(255) NOT NULL,
`CREATED_DATE` datetime NOT NULL,
`MODIFIED_BY` varchar(255) DEFAULT NULL,
`MODIFIED_DATE` datetime DEFAULT NULL,
PRIMARY KEY (`MW_REQUEST_PRN`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8
CREATE TABLE `TABLE_3` (
`FIELD_1` varchar(30) NOT NULL,
`Field_2` bigint(20) NOT NULL,
`FIELD_3` varchar(40) NOT NULL,
`CREATED_BY` varchar(255) NOT NULL,
`CREATED_DATE` datetime NOT NULL,
`MODIFIED_BY` varchar(255) DEFAULT NULL,
`MODIFIED_DATE` datetime DEFAULT NULL,
PRIMARY KEY (`FIELD_1`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8
CREATE TABLE `TABLE_1` (
`FIELD_1` bigint(20) NOT NULL,
`FIELD_3` bigint(20) NOT NULL,
`FIELD_2` bigint(20) NOT NULL,
`CREATED_BY` varchar(255) NOT NULL,
`CREATED_DATE` datetime NOT NULL,
`MODIFIED_BY` varchar(255) DEFAULT NULL,
`MODIFIED_DATE` datetime DEFAULT NULL,
PRIMARY KEY (`FIELD_1`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8