Skip to content

Criteria API(NativeSql)を使用した複数エンティティへの射影 #974

Closed Answered by nakamura-to
ironclad-15256304 asked this question in Q&A
Discussion options

You must be logged in to vote

下記のように一度RowのListで受け取り、1行ごとにRowを任意のEntity群に詰め替えてはいかがでしょうか?

Employee_ e = new Employee_();
Address_ a = new Address_();

List<Row> rows = nativeSql.from(e).leftJoin(a, ...).selectAsRow(e.employeeName, e.employeeNo, a.street).fetch();
List<Tuple2<Employee, Address>> list = rows.stream().map(row -> {...}); // EmployeeやAddressのエンティティに詰め替える

ドキュメントとしては下記を参照ください。
https://doma.readthedocs.io/en/latest/criteria-api/#column-projection-nativesql

Replies: 2 comments 2 replies

Comment options

You must be logged in to vote
1 reply
@ironclad-15256304
Comment options

Answer selected by ironclad-15256304
Comment options

You must be logged in to vote
1 reply
@ironclad-15256304
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants