Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You could take a look at <a href="http://www.springsource.org/spring-data/jpa" rel="noreferrer">Spring Data JPA</a>. It allows you to simply define an interface and execute queries without the need to implement the execution manually.</p> <p>Entity:</p> <pre><code>@Entity @NamedQuery(id="User.findByLastname" query="from User u where u.lastname = ?1") public class User implements Persistable&lt;Long&gt; { @Id private Long id; private String username; private String lastname; private int age; } </code></pre> <p>Repository:</p> <pre><code>public interface UserRepository extends CrudRepository&lt;User, Long&gt; { // Will trigger the NamedQuery due to a naming convention List&lt;User&gt; findByLastname(String lastname); // Will create a query from the methodname // from User u where u.username = ? User findByUsername(String username); // Uses query annotated to the finder method in case you // don't want to pollute entity with query info @Query("from User u where u.age &gt; ?1") List&lt;User&gt; findByAgeGreaterThan(int age); } </code></pre> <p>Setup:</p> <pre><code>EntityManager em = Persistence.getEntityManagerFactory().createEntityManager(); JpaRepositoryFactory factory = new JpaRepositoryFactory(em); UserRepository repository = factory.getRepository(UserRepository.class); </code></pre> <p>As you see you can choose between different ways to derive the query to be executed from the method. While deriving it directly from the method name is feasible for simple queries you'd probably choose between the <code>@NamedQuery</code> (JPA standard) or <code>@Query</code> (Spring Data JPA annotation) dependening on how much you like to stick with standards.</p> <p>Spring Data JPA gives you support in various other corners of data access layer implementation, allows providing custom implementations for methods and nicely integrates with Spring.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload