Hi Rob,
It is most likely related to column mapping as when I play around with query and it returns an empty list there is no error. But I thought that's related to where data is coming from.
I have also tried to bind it to @Entity like below, and to @Sql annotated aggregate class like in the example on Ebean webpage but with exactly same result.
Below I am including code that is related to the issue, it's trimmed down a lot as I was trying to get even basics working, I have also removed one @ManyToOne relation to avoid Lazy loading potential issues you have mentioned.
/* This exists in one database */
@Entity
@Table(name = "invoice_details")
public class InvoiceDetails extends Model {
@Column(name = "details_id")
@Id
@GeneratedValue(strategy = GenerationType.TABLE)
public Integer detailsId;
@Column(name = "invoice_no")
public String invoiceNo; // normally that is a foreign key
@Column(name = "ticket_no", length = 14)
public String ticketNo;
@Column(name = "coupon_no", length = 1)
public String couponNo;
}
/* query below is trying to get data from different tables in external DB and bind them to details */
String sqlTest = "SELECT " +
"tt.ticket_number, " +
"tc.coupon_information_number " +
"FROM tkt_coupon tc " +
"INNER JOIN tkt_ticket tt " +
"ON tc.tkt_ticket_id = tt.tkt_ticket_id ";
RawSql testRaw = RawSqlBuilder.parse(sqlTest)
.columnMapping("tt.ticket_number", "ticketNo")
.columnMapping("tc.coupon_information_number", "couponNo")
.create();
Query<InvoiceDetails> queryDetails = server.find(InvoiceDetails.class);
queryDetails.setRawSql(testRaw)
.where()
.eq("MONTH(tc.travel_product_date)", 3)
.eq("YEAR(tc.travel_product_date)", 2015);
return queryDetails.findList(); // This is where it fails with error
[PersistenceException: Query threw SQLException:Column Index out of
range, 0 < 1.
Bind values:[3,2015]
Query was:
select tt.ticket_number, tc.coupon_information_number FROM tkt_coupon tc
INNER JOIN tkt_ticket tt ON tc.tkt_ticket_id = tt.tkt_ticket_id INNER
JOIN tkt_ticket_passenger tp ON tp.tkt_ticket_passenger_id =
tt.tkt_ticket_passenger_id where MONTH(tc.travel_product_date) = ? and
YEAR(tc.travel_product_date) = ?
]