Ebean Partial Column Selection

Okay, because of some reasons, I have to learn Java and choose a Java web framework for my next project. After seeing around, I choose playframework, and I am using MySQL for the database.

After reading some documentation, I use Evolution and Ebean for the ORM. And then I found a problem when using Ebean. It still returning all columns although I selected some columns with this method based on this documentation.

List<MyModel> getUser = MyModel.find.select("columnA, columnB").findList()

After searching some solutions on google, I found this solution. So you have to do it like this.

JsonContext jc = Ebean.json();
List<MyModel> getUser = MyModel.find.select("columnA, columnB").findList();
String allUser = jc.toJson(getUser);

But when you use this method, the type of result will be a string type, so do not forget using Json.parse() if you want to use it as an object.

You may also like

Leave a Reply

Your email address will not be published. Required fields are marked *