HHH-17729 move validation of constructors in HQL instantiations to SemanticQueryBuilder

test for query method generation
This commit is contained in:
Gavin King 2024-02-11 13:57:52 +01:00
parent 24937b4e67
commit d09d6ffdf0
3 changed files with 51 additions and 0 deletions

View File

@ -5,6 +5,8 @@ import jakarta.persistence.Id;
import jakarta.persistence.ManyToOne; import jakarta.persistence.ManyToOne;
import org.hibernate.annotations.NaturalId; import org.hibernate.annotations.NaturalId;
import java.math.BigDecimal;
@Entity @Entity
public class Book { public class Book {
@Id String isbn; @Id String isbn;
@ -12,4 +14,6 @@ public class Book {
String text; String text;
@NaturalId String authorName; @NaturalId String authorName;
@ManyToOne Publisher publisher; @ManyToOne Publisher publisher;
BigDecimal price;
int pages;
} }

View File

@ -47,4 +47,8 @@ public interface Dao {
@HQL("from Book book join fetch book.publisher where book.title like :titlePattern") @HQL("from Book book join fetch book.publisher where book.title like :titlePattern")
List<Book> booksWithPublisherByTitle(String titlePattern, Page page, Order<? super Book> order); List<Book> booksWithPublisherByTitle(String titlePattern, Page page, Order<? super Book> order);
@HQL("select new org.hibernate.jpamodelgen.test.hqlsql.Dto(title, pages) from Book")
List<Dto> dtoQuery();
} }

View File

@ -0,0 +1,43 @@
package org.hibernate.jpamodelgen.test.hqlsql;
import java.util.Objects;
public final class Dto {
private final String title;
private final int pages;
public Dto(String title, int pages) {
this.title = title;
this.pages = pages;
}
public String title() {
return title;
}
public int pages() {
return pages;
}
@Override
public boolean equals(Object obj) {
if (obj == this) return true;
if (obj == null || obj.getClass() != this.getClass()) return false;
var that = (Dto) obj;
return Objects.equals(this.title, that.title) &&
this.pages == that.pages;
}
@Override
public int hashCode() {
return Objects.hash(title, pages);
}
@Override
public String toString() {
return "Dto[" +
"title=" + title + ", " +
"pages=" + pages + ']';
}
}