Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to comment (javadoc) NamedQueries

Assume there are some named queries in an entity, how should those named queries be commented? Is there a way to map them into the created javadoc?

  @Entity
    @NamedQueries({
        @NamedQuery(name="Country.findAll",
                    query="SELECT c FROM Country c"),
        @NamedQuery(name="Country.findByName",
                    query="SELECT c FROM Country c WHERE c.name = :name"),
    }) 
    public class Country {
      ...
    }

At the moment I put comments (non javadoc) in the line before but I don't like it very much.

// find all countries
@NamedQuery(name="Country.findAll", query="SELECT c FROM Country c")
like image 295
aldebaran-ms Avatar asked Sep 02 '25 18:09

aldebaran-ms


1 Answers

I use to define the Query's name as a constant inside of the entity class. That constant can of course be commented:

@Entity
@NamedQueries({
@NamedQuery(name=Country.QUERY_FIND_BY_NAME,
            query="SELECT c FROM Country c WHERE c.name = :name"),
}) 
public class Country {

    /**
     * Description of the Query. Bla bla.
     */
    public static final String QUERY_FIND_BY_NAME = "Country.findByName";

   ...
}

As a bonus, you can use this constant instead of a String when creating a named query:

em.createNamedQuery(Country.QUERY_FIND_BY_NAME, Country.class);
like image 104
Christoph Giesche Avatar answered Sep 04 '25 07:09

Christoph Giesche