Q:

Coding Style: Is it acceptable to make further queries from within model classes?

I have a model class Alert with a one-to-many relationship with another model class Occurrence, as follows:
@Entity public class Alert extends Model
{
  public String name;

  @OneToMany(cascade=CascadeType.ALL, fetch=FetchType.LAZY, mappedBy="alert")
  public List<Occurrence> occurrences;
}

@Entity public class Occurrence extends Model
{
  @ManyToOne
  public Alert alert;

  @Column(nullable=false)
  public Date alertTime;
}

I have a view that lists Alerts in a simple table, which should have a column labelled "Occurrences today", with a count of how many occurrences of the alert have happened today (by alertTime).
I can't seem to find a way to do this using only JPA/Hibernate annotations in the Alert model class, and since I am listing Alerts, I don't know of a clean way to include the count in each Alert object.
So now I am wondering if it would be fine to simply query for the alert's occurrences from within the Alert model class itself, like so:
@Entity public class Alert extends Model
{
  public String name;

  @OneToMany(cascade=CascadeType.ALL, fetch=FetchType.LAZY, mappedBy="alert")
  public List<Occurrence> occurrences;

  @Transient
  public long getOccurrencesToday()
  {
    return Occurrence.count(
      "alert = ? and alertTime >= ?",
      this, new DateMidnight().toDate());
  }
}

My question is: Is it considered bad form to make queries to the DB from within a model class?
A secondary question is: Am I approaching this the wrong way? Is there a better way to achieve the end result that I've missed?

A:

While your approach is tempting, its dangerous because effectively you're putting logic into a "getter" (getOccurrencesToday()) which you'll probably access by ${alert.occurrencesToday}
A getter should always be side effect free. 
I would change this to 
@Entity public class Alert extends Model
{
  public String name;

  @OneToMany(cascade=CascadeType.ALL, fetch=FetchType.LAZY, mappedBy="alert")
  public List<Occurrence> occurrences;

  @Transient public Long occurrencesToday = null;

  public void populateOccurrencesToday()
  {
    occurrencesToday = Occurrence.count(
      "alert = ? and alertTime >= ?",
      this, new DateMidnight().toDate());
  }
}

then in your controller, iterate over all alerts that 
you're going to render and execute the populateOccurrencesToday() method. 
If you're now storing your object in a cache, its data will be consistent. 

