When I use Dynamic mapping on a field for an entity like below
@Entity
class Company{
//other fields removed
@Formula("select count(c.id) from Contact c where c.company_id = id")
private int contactCount;
}
I get the following error when I fetch companies from db.
you have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use
But when I change my formula to
@Formula("(select count(c.id) from Contact c where c.company_id = id)")
private int contactCount;
everything works correctly. What's effect of paranthesis at the end and beginning of the formula?