Commit 72d4a049 authored by Thomas Lang's avatar Thomas Lang
Browse files

added test files and test itself

parent 1ac7ec4c
# Test Template
## Hibernate Issue HHH-12119
Linked here:
https://hibernate.atlassian.net/browse/HHH-12119
## Database Dump:
Please use the attached database dump file (rechnung in the folder resources - postgresql format) to setup your database.
Test data is included.
## Test:
Please run the test.
The following query should be executed:
`select i.invoice_id as "invoiceId", i.booking_tag as "bookingTag", i.invoice_number as "invoiceNumber", i.created_by as "createdBy", i.invoice_api_groups as "apiGroups", i.invoice_date as "invoiceDate", r.recipient as "recipient" from invoice i inner join recipient r on (i.recipient_recipient_id = r.recipient_id) where i.invoice_state = 0 and i.invoice_api_groups similar to '%tlang%|%Seminare%' order by i.invoice_date desc`
## Result:
The query gets executed the right way and yields some results.
With Spring Data JPA i want to use a projection interface.
As you have stated to explicitly not use Spring, the test does not
show the issue in the correct manner.
However the mentioned interface is integrated in the project - see `InvoiceProjection`
\ No newline at end of file
package org.hibernate.bugs;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
import javax.persistence.Query;
import java.util.List;
/**
* This template demonstrates how to develop a test case for Hibernate ORM, using the Java Persistence API.
*/
......@@ -28,10 +30,14 @@ public class JPAUnitTestCase {
// Entities are auto-discovered, so just add them anywhere on class-path
// Add your tests, using standard JUnit.
@Test
public void hhh123Test() throws Exception {
public void hhh12119Test() throws Exception {
EntityManager entityManager = entityManagerFactory.createEntityManager();
entityManager.getTransaction().begin();
// Do stuff...
final Query query = entityManager.createNativeQuery("select i.invoice_id as \"invoiceId\", i.booking_tag as \"bookingTag\", i.invoice_number as \"invoiceNumber\", i.created_by as \"createdBy\", i.invoice_api_groups as \"apiGroups\", i.invoice_date as \"invoiceDate\", r.recipient as \"recipient\" from invoice i inner join recipient r on (i.recipient_recipient_id = r.recipient_id) where i.invoice_state = 0 and i.invoice_api_groups similar to '%tlang%|%Seminare%' order by i.invoice_date desc");
final List resultList = query.getResultList();
entityManager.getTransaction().commit();
entityManager.close();
}
......
package org.hibernate.bugs.db;
import java.time.LocalDate;
/**
* Projection interface for spring data jpa.
* takes the resultset of a spring data jpa query.
*
* @author tlang
*/
public interface InvoiceProjection {
/**
* The invoice id.
*
* @return long
*/
long getInvoiceId();
/**
* The booking tag.
*
* @return String
*/
String getBookingTag();
/**
* The invoice number.
*
* @return String
*/
String getInvoiceNumber();
/**
* The invoice date.
*
* @return LocalDate
*/
LocalDate getInvoiceDate();
/**
* The invoice recipient.
*
* @return String
*/
String getRecipient();
/**
* The invoice state
*
* @return InvoiceState
*/
InvoiceState getInvoiceState();
/**
* The created by property.
*
* @return String
*/
String getCreatedBy();
/**
* The modified by property.
*
* @return String
*/
String getModifiedBy();
/**
* The api groups projection.
*
* @return String
*/
String getApiGroups();
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment