Property with @Formula and @Transient getting only null value

1,385 views
Skip to first unread message

Sivakumar Raja

unread,
May 19, 2015, 3:08:59 AM5/19/15
to eb...@googlegroups.com
Hi all,

Model People



   
@Entity
   
@Table(name="people")
   
public class People extends Model {

       
@Id
       
@GeneratedValue(strategy = GenerationType.AUTO)
       
public int id;
       
       
public String name;
       
       
public String location;
       
       
@Transient
       
@Formula(select = "(SELECT ISNULL(`name`) + ISNULL(`location`) Num_Null FROM `people` where id = ${ta}.id )")
       
public String count;

       
....
   
}

Query

 List<People> records = find.select("id, count").findList();

     When i run the above query, the resultant object has values for id field, but null for count field. If i remove the @Transient annotation it works perfectly, but i don't want the formula to execute for every query. So in order to restrict, i am using @Transient annotation.

     When i run the ebean generated SQL query in Mysql workbench, it shows the value for both id and count fields. Please help me to sort this issue.

Thanks,
Sivakumar.R

Daryl Stultz

unread,
May 19, 2015, 7:54:50 AM5/19/15
to eb...@googlegroups.com
On Tue, May 19, 2015 at 3:08 AM, Sivakumar Raja <sivar...@gmail.com> wrote:

     When i run the above query, the resultant object has values for id field, but null for count field. If i remove the @Transient annotation it works perfectly, but i don't want the formula to execute for every query. So in order to restrict, i am using @Transient annotation.

@Transient fields are ignored. @Formula fields are executed only when you explicitly select it.

/Daryl

Sivakumar Raja

unread,
May 19, 2015, 10:30:26 AM5/19/15
to eb...@googlegroups.com
Hi Daryl,

    That's what i have done here, List<People> records = find.select("id, count").findList();
 
  In my case, count field is the one with @Transient and @Formula annotation. I already mentioned count field in my select statement.

  Please correct me, if i have done anything wrong.

Thanks,
Sivakumar.R

--

---
You received this message because you are subscribed to a topic in the Google Groups "Ebean ORM" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ebean/Q8Xgtla0X4k/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ebean+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Daryl Stultz

unread,
May 19, 2015, 10:33:54 AM5/19/15
to eb...@googlegroups.com
On Tue, May 19, 2015 at 10:30 AM, Sivakumar Raja <sivar...@gmail.com> wrote:
Hi Daryl,

    That's what i have done here, List<People> records = find.select("id, count").findList();
 
  In my case, count field is the one with @Transient and @Formula annotation. I already mentioned count field in my select statement.

  Please correct me, if i have done anything wrong.

Take the @Transient off and show that it still works. Then take the count field out of the select and show that the field is null. You said you don't want the formula run every time. You said you put in @Transient for this purpose, but the thing to do is simply leave the @Formula column out of the select.

/Daryl

Reply all
Reply to author
Forward
0 new messages