testing HQL query on hbm2dll with Junit
<p>How can I test HQL query with JUnit tests?</p>

<p>I have mapped Entity Class:</p>

<pre><code>@Entity
@Table(name = "DOE")
public DomainObjectEntity {
    //some attributes
}
</code></pre>

<p>which represents domain objects:</p>

<pre><code>public class DomainObject {
     //some attributes
}
</code></pre>

<p>I also have repository interface for my domain objects:</p>

<pre><code> public interface DomainObjectRepository {

     /**
     * Gets entity by some attribute
     * 
     */
     DomainObject getDomainObjectByObjectId(String objectId);
}
</code></pre>

<p>this interface is implemented in </p>

<pre><code> @Repository
 public class DomainObjectRepositoryImpl implements DomainObjectRepository {

     @Inject
     private DomainObjectEntityJPARepository entityRepository;

    @Override
     public DomainObjectgetDomainObjectById(String parcelId) {
        //this converts my entity to domain object
        return entityRepository.findByDomainObjectId(DomainObjectId.getStr()).getDomainObject(); 
    }

}
</code></pre>

<p>my JPA Entity repository looks like this:</p>

<pre><code>public interface DomainObjectEntityJPARepository extends  JpaRepository&lt;DomainObjectEntity, String&gt; {
    /**
     * get DomainObject with requested id
     * 
     * @param objectId - objects id
     * @return DomainObject
     */
    @Query("some query to be tested")
    DomainObjectEntity findByDomainObjectId(@Param("objectId") String objectId);
}
</code></pre>

<p>and finally i want to write a simple JUnit test to check if query to <code>findByDomainObjectId</code> returns the correct object. I think my test should look like this:</p>

<ol>
<li>create test object to put into DB</li>
<li>retrieve object from DB</li>
<li>compare objects</li>
</ol>

<p>i have setted up a hbm2dll with import.sql to create and populate my DB but how can i access it from Junit test by calling method <code>findByDomainObjectId</code>?</p>