On 15.6.23 14:17, Thiago H. de Paula Figueiredo wrote:
Yeah, it doesn't seem to happen for everyone. tapestry-hibernate has
unit and integration tests and they have been successful.
For me, it is very easy to reproduce. I can share the entire source
code, but there is nothing special to share.
I start with the tapestry quick-start, add tapestry-hibernate and
postgresql driver in the pom.xml, add just one entity class named Book
(id, title and description and respective getter/setters) and modify the
About page to be really simple:
import java.util.List;
import org.apache.tapestry5.ioc.annotations.Inject;
import org.hibernate.Session;
import test.testhql.entities.Book;
public class TestPage {
@Inject
private Session session;
public List<Book> getListOfBooks() {
// this does not work
return session.createQuery("from Book").list();
// this works
//return session.getSession().createQuery("from Book").list();
// this works too
//return session.createCriteria(Book.class).list();
}
}
And the result is an error with this as the main problem:
Caused by: java.lang.NullPointerException: Cannot invoke
"org.hibernate.query.Query.list()" because the return value of
"org.hibernate.Session.createQuery(String)" is null
The rest of the code:
TML File:
<html t:type="layout" title="About | testhql"
xmlns:t="http://tapestry.apache.org/schema/tapestry_5_4.xsd"
xmlns:p="tapestry:parameter">
<t:grid t:source="listOfBooks" />
</html>
Entity class:
package test.testhql.entities;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
@Entity
@Table(name = "book", schema = "public")
public class Book {
private long bookId;
private String title;
private String description;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "book_id", unique = true, nullable = false)
public long getBookId() {
return bookId;
}
public void setBookId(long bookId) {
this.bookId = bookId;
}
@Column(name = "title", unique = false, nullable = false)
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
@Column(name = "description", unique = false, nullable = true,
length = 10000000)
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
}
in case it matters:
The results is the same if I run the app from Eclipse flatpak (on Fedora
Silverblue, so should be reproducible), or if I run it from a
commandline using SDKMAN managed Maven and JDK.
Apache Maven 3.9.1 (2e178502fcdbffc201671fb2537d0cb4b4cc58f8)
Maven home: ~/.sdkman/candidates/maven/current
Java version: 17.0.6, vendor: Eclipse Adoptium, runtime:
~/.sdkman/candidates/java/17.0.6-tem
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "6.3.7-200.fc38.x86_64", arch: "amd64",
family: "unix"
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
For additional commands, e-mail: users-h...@tapestry.apache.org