Skip to content

Instantly share code, notes, and snippets.

@yanaga
Created June 4, 2012 14:40
Show Gist options
  • Save yanaga/2868795 to your computer and use it in GitHub Desktop.
Save yanaga/2868795 to your computer and use it in GitHub Desktop.
JpaQueryDslRepository.java
import java.io.Serializable;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import com.mysema.query.jpa.JPQLQuery;
import com.mysema.query.jpa.impl.JPAQuery;
public class JpaQueryDslRepository implements QueryDslRepository {
@PersistenceContext
private EntityManager entityManager;
@Override
public <T> T save(T entity) {
return entityManager.merge(entity);
}
@Override
public <T> T remove(T entity) {
entityManager.remove(entity);
return entity;
}
@Override
public <T> T findById(Class<T> klazz, Serializable id) {
return entityManager.find(klazz, id);
}
@Override
public JPQLQuery query() {
return new JPAQuery(entityManager);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment