Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
HHH-11500 - Provide the cause of the error when validating @loader na…
…med queries
- Loading branch information
1 parent
d80c6ac
commit c434d9a
Showing
2 changed files
with
103 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
95 changes: 95 additions & 0 deletions
95
...-core/src/test/java/org/hibernate/test/annotations/loader/LoaderWithInvalidQueryTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
/* | ||
* Hibernate, Relational Persistence for Idiomatic Java | ||
* | ||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later. | ||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>. | ||
*/ | ||
package org.hibernate.test.annotations.loader; | ||
|
||
import javax.persistence.Column; | ||
import javax.persistence.Entity; | ||
import javax.persistence.GeneratedValue; | ||
import javax.persistence.Id; | ||
|
||
import org.hibernate.HibernateException; | ||
import org.hibernate.annotations.Loader; | ||
import org.hibernate.annotations.NamedNativeQueries; | ||
import org.hibernate.annotations.NamedQuery; | ||
import org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase; | ||
|
||
import org.hibernate.testing.util.ExceptionUtil; | ||
import org.junit.Test; | ||
|
||
import static org.junit.Assert.assertTrue; | ||
|
||
/** | ||
* @author Vlad Mihalcea | ||
*/ | ||
public class LoaderWithInvalidQueryTest extends BaseEntityManagerFunctionalTestCase { | ||
|
||
@Override | ||
protected Class<?>[] getAnnotatedClasses() { | ||
return new Class<?>[] { | ||
Person.class | ||
}; | ||
} | ||
|
||
@Override | ||
public void buildEntityManagerFactory() throws Exception { | ||
try { | ||
super.buildEntityManagerFactory(); | ||
} | ||
catch (Exception expected) { | ||
HibernateException rootCause = (HibernateException) ExceptionUtil.rootCause( expected ); | ||
assertTrue(rootCause.getMessage().contains( "could not resolve property: valid" )); | ||
assertTrue(rootCause.getMessage().contains( "_Person is not mapped" )); | ||
} | ||
} | ||
|
||
@Test | ||
public void test() { | ||
} | ||
|
||
|
||
@Entity(name = "Person") | ||
@Loader(namedQuery = "invalid_sql") | ||
@NamedQuery( | ||
name = "invalid_sql", | ||
query = "SELECT p " + | ||
"FROM Person p " + | ||
"WHERE p.id = ? and p.valid = true" | ||
) | ||
@NamedQuery( | ||
name = "another_invalid_sql", | ||
query = "SELECT p " + | ||
"FROM _Person p " + | ||
"WHERE p.id = ?" | ||
) | ||
public static class Person { | ||
|
||
@Id | ||
@GeneratedValue | ||
private Long id; | ||
|
||
@Column(name = "full_name") | ||
private String name; | ||
|
||
public Long getId() { | ||
return id; | ||
} | ||
|
||
public void setId(Long id) { | ||
this.id = id; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public void setName(String name) { | ||
this.name = name; | ||
} | ||
} | ||
//end::sql-custom-crud-example[] | ||
|
||
} |