Most likely your entity manager isn't getting initialized, and that's where
the NPE is coming from. Try breaking down listBooks(), assigning each call
to a variable before accessing it, like so:
EntityManager em = Stipersist.getEntityManager();
Query query = em.createQuery("from Book");
List books = query.getResultList();
log.debug("Got " + books.size() + " books");
return books;
The stack trace will show the line where the NPE happens, and it will be
clear what is null. Really, though, if it is in listBooks() it's almost
certainly the entity manager that is null.
You should set the log level to debug for org.stripesstuff so you can see
exactly what it's doing. If the entity manager is null, then it's because
Stripersist isn't initializing properly.
What version of Stripes are you using and what app server?
-Ben
On Mon, Oct 26, 2009 at 4:30 PM, Dan King <[email protected]> wrote:
> I've put together a simple persistence example, but unfortunately it
> doesn't work and I can't figure out why (I originally thought I was misusing
> Stripersist, but after some clarification realized that was not the case).
> Following are the pertinent pieces of code, if anyone sees what is wrong
> please let me know. Note: the error stack shows NullPointerException -
> practice.example.dao.BookDao.listBooks (BookDao.java:16)
> .
>
> /* BookDao.java */
> public class BookDao {
> @SuppressWarnings("unchecked")
> public List<Book> listBooks(){
> return Stripersist.getEntityManager().createQuery("from
> Book").getResultList();
> }
> }
>
> /* Book.java */
> @Entity
> @Table(name="books")
> public class Book {
>
> @Id
> @GeneratedValue
> @Column(name="id")
> private int id;
>
> @Column(name="title")
> private String title;
>
> @Column(name="author_name")
> private String authorName;
>
> public int getId() {
> return id;
> }
> public void setId(int id) {
> this.id = id;
> }
>
> /* The remaining getters/setters and an empty constructor */
>
> -Dan
>
>
>
>
>
>
> ------------------------------------------------------------------------------
> Come build with us! The BlackBerry(R) Developer Conference in SF, CA
> is the only developer event you need to attend this year. Jumpstart your
> developing skills, take BlackBerry mobile applications to market and stay
> ahead of the curve. Join us from November 9 - 12, 2009. Register now!
> http://p.sf.net/sfu/devconference
> _______________________________________________
> Stripes-users mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/stripes-users
>
------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
Stripes-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/stripes-users