我在数据库中有一个视图,我在其上构建了一个REST API。 REST API的输出看起来像两个表的笛卡尔积,它们是视图的一部分。任何人都有任何想法为什么会发生?
以下是JSON和SQL的相关java,sql代码和输出
Bulkdeals.java
@Entity
@Table(name = "BULKDEALS")
@XmlRootElement
@NamedQueries({
@NamedQuery(name = "Bulkdeals.findAll", query = "SELECT b FROM Bulkdeals b"),
@NamedQuery(name = "Bulkdeals.findByTradeDate", query = "SELECT b FROM Bulkdeals b WHERE b.tradeDate = :tradeDate"),
@NamedQuery(name = "Bulkdeals.findByDate", query = "SELECT b FROM Bulkdeals b WHERE b.tradeDate BETWEEN :tradeDate1 AND :tradeDate2")
})
BulkdealsFacadeREST.java
//Usage: http://localhost:8080/MA/webresources/db.bulkdeals/date/29-JUL-15
@GET
@Path("/date/{Fordate}")
@Produces({ MediaType.APPLICATION_JSON})
public List<Bulkdeals> findRange(@PathParam("Fordate") Date tradeDate) {
return (List<Bulkdeals>) em.createNamedQuery("Bulkdeals.findByTradeDate").setParameter("tradeDate", tradeDate).getResultList();
}
//Usage: http://localhost:8080/MA/webresources/db.bulkdeals/date/29-JUL-15/05-SEP-2016
@GET
@Path("/date/{Fromdate}/{Todate}")
@Produces({ MediaType.APPLICATION_JSON})
public List<Bulkdeals> findRange1( @PathParam("Fromdate") Date tradeDate1, @PathParam("Todate") Date tradeDate2 ) {
return (List<Bulkdeals>) em.createNamedQuery("Bulkdeals.findByDate").setParameter("tradeDate1", tradeDate1).setParameter("tradeDate2", tradeDate2).getResultList();
}
查看
CREATE OR REPLACE FORCE EDITIONABLE VIEW "TA_USER"."BULKDEALS"
("TRADE_DATE", "SYMBOL", "NAME", "CLIENT", "BUYSELL", "QUANTITY", "TRADEPRICE") AS
SELECT TRADE_DATE, SYMBOL, NAME, CLIENT, BUYSELL, QUANTITY, TRADEPRICE
FROM STOCKS_DW.TB_BLOCKDEALS
union
SELECT TRADE_DATE, SYMBOL, NAME, CLIENT, BUYSELL, QUANTITY,TRADEPRICE
FROM STOCKS_DW.TB_BULKDEALS
order by 1 desc;
JSON
{"bulkdeals":[{"buysell":"SELL","client":"ASHISH DHAWAN","name":"Allsec Technologies Limit","quantity":99744,"symbol":"ALLSEC","tradeDate":"2015-07-29T00:00:00+05:30","tradeprice":34},
{"buysell":"SELL","client":"ASHISH DHAWAN","name":"Allsec Technologies Limit","quantity":99744,"symbol":"ALLSEC","tradeDate":"2015-07-29T00:00:00+05:30","tradeprice":34},
{"buysell":"SELL","client":"ASHISH DHAWAN","name":"Allsec Technologies Limit","quantity":99744,"symbol":"ALLSEC","tradeDate":"2015-07-29T00:00:00+05:30","tradeprice":34},
{"buysell":"SELL","client":"ASHISH DHAWAN","name":"Allsec Technologies Limit","quantity":99744,"symbol":"ALLSEC","tradeDate":"2015-07-29T00:00:00+05:30","tradeprice":34},{"buysell":"SELL","client":"ASHISH DHAWAN","name":"Allsec Technologies Limit","quantity":99744,"symbol":"ALLSEC","tradeDate":"2015-07-29T00:00:00+05:30","tradeprice":34},
{"buysell":"SELL","client":"ASHISH DHAWAN","name":"Allsec Technologies Limit","quantity":99744,"symbol":"ALLSEC","tradeDate":"2015-07-29T00:00:00+05:30","tradeprice":34},
{"buysell":"SELL","client":"ASHISH DHAWAN","name":"Allsec Technologies Limit","quantity":99744,"symbol":"ALLSEC","tradeDate":"2015-07-29T00:00:00+05:30","tradeprice":34},{"buysell":"SELL","client":"ASHISH DHAWAN","name":"Allsec Technologies Limit","quantity":99744,"symbol":"ALLSEC","tradeDate":"2015-07-29T00:00:00+05:30","tradeprice":34},{"buysell":"SELL","client":"ASHISH DHAWAN","name":"Allsec Technologies Limit","quantity":99744,"symbol":"ALLSEC","tradeDate":"2015-07-29T00:00:00+05:30","tradeprice":34},{"buysell":"SELL","client":"ASHISH DHAWAN","name":"Allsec Technologies Limit","quantity":99744,"symbol":"ALLSEC","tradeDate":"2015-07-29T00:00:00+05:30","tradeprice":34},{"buysell":"SELL","client":"ASHISH DHAWAN","name":"Allsec Technologies Limit","quantity":99744,"symbol":"ALLSEC","tradeDate":"2015-07-29T00:00:00+05:30","tradeprice":34},{"buysell":"SELL","client":"ASHISH DHAWAN","name":"Allsec Technologies Limit","quantity":99744,"symbol":"ALLSEC","tradeDate":"2015-07-29T00:00:00+05:30","tradeprice":34},{"buysell":"SELL","client":"ASHISH DHAWAN","name":"Allsec Technologies Limit","quantity":99744,"symbol":"ALLSEC","tradeDate":"2015-07-29T00:00:00+05:30","tradeprice":34},{"buysell":"SELL","client":"ASHISH DHAWAN","name":"Allsec Technologies Limit","quantity":99744,"symbol":"ALLSEC","tradeDate":"2015-07-29T00:00:00+05:30","tradeprice":34},{"buysell":"SELL","client":"ASHISH DHAWAN","name":"Allsec Technologies Limit","quantity":99744,"symbol":"ALLSEC","tradeDate":"2015-07-29T00:00:00+05:30","tradeprice":34},{"buysell":"SELL","client":"ASHISH DHAWAN","name":"Allsec Technologies Limit","quantity":99744,"symbol":"ALLSEC","tradeDate":"2015-07-29T00:00:00+05:30","tradeprice":34},{"buysell":"SELL","client":"ASHISH DHAWAN","name":"Allsec Technologies Limit","quantity":99744,"symbol":"ALLSEC","tradeDate":"2015-07-29T00:00:00+05:30","tradeprice":34},{"buysell":"SELL","client":"ASHISH DHAWAN","name":"Allsec Technologies Limit","quantity":99744,"symbol":"ALLSEC","tradeDate":"2015-07-29T00:00:00+05:30","tradeprice":34},{"buysell":"SELL","client":"ASHISH DHAWAN","name":"Allsec Technologies Limit","quantity":99744,"symbol":"ALLSEC","tradeDate":"2015-07-29T00:00:00+05:30","tradeprice":34},{"buysell":"SELL","client":"ASHISH DHAWAN","name":"Allsec Technologies Limit","quantity":99744,"symbol":"ALLSEC","tradeDate":"2015-07-29T00:00:00+05:30","tradeprice":34},{"buysell":"SELL","client":"ASHISH DHAWAN","name":"Allsec Technologies Limit","quantity":99744,"symbol":"ALLSEC","tradeDate":"2015-07-29T00:00:00+05:30","tradeprice":34},{"buysell":"SELL","client":"ASHISH DHAWAN","name":"Allsec Technologies Limit","quantity":99744,"symbol":"ALLSEC","tradeDate":"2015-07-29T00:00:00+05:30","tradeprice":34},{"buysell":"SELL","client":"ASHISH DHAWAN","name":"Allsec Technologies Limit","quantity":99744,"symbol":"ALLSEC","tradeDate":"2015-07-29T00:00:00+05:30","tradeprice":34}]}
SQL OUTPUT
SELECT TRADE_DATE, SYMBOL, NAME, CLIENT, BUYSELL, QUANTITY, TRADEPRICE FROM BULKDEALS where trade_date = '29-JUL-2015' ;
29-JUL-15 ALLSEC Allsec Technologies Limit ASHISH DHAWAN SELL 99744 34
29-JUL-15 ARCHIDPLY Archidply Industries Limi BP FINTRADE PRIVATE LIMITED BUY 129910 53.98
29-JUL-15 ARCHIDPLY Archidply Industries Limi BP FINTRADE PRIVATE LIMITED SELL 124880 54.09
29-JUL-15 BROOKS Brooks Lab Limited GKN SECURITIES BUY 84900 85.54
29-JUL-15 BROOKS Brooks Lab Limited GKN SECURITIES SELL 84900 84.13
29-JUL-15 CEREBRAINT Cerebra Int Tech Ltd SHAH NIRAJ RAJNIKANT BUY 49036 15.14
29-JUL-15 CEREBRAINT Cerebra Int Tech Ltd SHAH NIRAJ RAJNIKANT SELL 490000 15.23
29-JUL-15 DOLPHINOFF Dolphin Offshore Enterpri CREST CAPITAL & INVESTMENT BUY 111000 122.01
29-JUL-15 DOLPHINOFF Dolphin Offshore Enterpri PRIYANKA FINANCE PVT LTD SELL 100000 121
29-JUL-15 GMBREW GM Breweries Ltd. BP FINTRADE PRIVATE LIMITED BUY 153273 302.21
29-JUL-15 GMBREW GM Breweries Ltd. BP FINTRADE PRIVATE LIMITED SELL 147521 303.78