Hallo,
I am new to Glassfish. I am trying to build a small sample application.
I use Glassfish V3 and Derby 10.6
I deploy everything in single war file.
The tables get created automatically and saving entities works fine. However when I run a NamedQuery I get the following exeption:
Caused by: java.lang.UnsupportedOperationException
at org.eclipse.persistence.internal.jpa.EntityManagerImpl.createNamedQuery(EntityManagerImpl.java:974)
at com.sun.enterprise.container.common.impl.EntityManagerWrapper.createNamedQuery(EntityManagerWrapper.java:555)
at ejb.BookDAO.findBooks(BookDAO.java:19)
--------------------------------------------------------------------------
package ejb;
import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.TypedQuery;
import entities.Book;
@Stateless
public class BookDAO {
@PersistenceContext(unitName="book")
private EntityManager entityManager;
public List<Book> findBooks() {
TypedQuery<Book> query = entityManager.createNamedQuery("findAllBooks", Book.class);
return query.getResultList();
}
public Book createBook(Book book) {
entityManager.persist(book);
return book;
}
}
-------------------------------------------------------------------------------------------
package entities;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.NamedQuery;
@Entity
@NamedQuery(name="findAllBooks", query="SELECT b FROM Book b")
public class Book {
@Id @GeneratedValue
private long id;
@Column(nullable=false)
private String title;
private Float price;
@Column(length=2000)
private String description;
private String isbn;
private Integer nbOfPage;
private Boolean illustrations;
//Getters and setters
---------------------------------------------------------------------------------------------
persistence.xml:
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="1.0" xmlns="
http://java.sun.com/xml/ns/persistence">
<persistence-unit name="book" transaction-type="JTA">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<jta-data-source>jdbc/books</jta-data-source>
<class>entities.Book</class>
<properties>
<property name="eclipselink.target-database" value="DERBY"/>
<property name="eclipselink.jdbc.driver" value="org.apache.derby.jdbc.ClientDriver"/>
<property name="eclipselink.jdbc.url" value="jdbc:derby://localhost:1527/books;create=true"/>
<!--<property name="eclipselink.jdbc.driver" value="org.apache.derby.jdbc.EmbeddedDriver"/>-->
<!--<property name="eclipselink.jdbc.url" value="jdbc:derby:chapter10DB;create=true"/>-->
<property name="eclipselink.jdbc.user" value="APP"/>
<property name="eclipselink.jdbc.password" value="APP"/>
<!--property name="eclipselink.ddl-generation" value="update"/-->
<property name="eclipselink.ddl-generation" value="drop-and-create-tables"/>
<property name="eclipselink.logging.level" value="INFO"/>
</properties>
</persistence-unit>
</persistence>
---------------------------------------------------------------------------
Any help would be greatly appreciated.
[Message sent by forum member 'hmrupp']
http://forums.java.net/jive/thread.jspa?messageID=485299