Optim queries in jpa mapping