Formula must be a valid sql. I would write it like with {alias} placehoder which reference table in from clause. Hibernate will replace alias with alias to 'a' table.
@Formula("(SELECT COUNT(*) FROM b WHERE b.a_id = {alias}.id)")