Gabor,
sorry for responding not earlier.
>> I am using JPA inside of a JAX-RS resource. When running it standalone it
>> works pretty well, but now I want to deploy it into GlassFish. I can deploy
>> it and all is working well but not the JPA. It can create an EntityManager,
>> but it doesn't find my @NamedQueries anymore! Anybody an idea what I have to
>> change?
>I run a JPA-backed Jersey service on glassfish just fine, no named
>queries though.
>Idea: what persistence provider do you specify in the persistence.xml?
Here is my persistence.xml file, located in JaxRsSample.war\WEB-INF\classes\META-INF\:
- <#> <persistence xmlns="*
http://java.sun.com/xml/ns/persistence*"
version="*1.0*">
- <#> <persistence-unit name="*X*" transaction-type="*JTA*">
<provider>oracle.toplink.essentials.ejb.cmp3.EntityManagerFactoryProvider</provider>
<jta-data-source>jdbc/X/5</jta-data-source>
<class>mk.jpa.Article</class>
<class>mk.jpa.Person</class>
- <#> <properties>
<property name="*toplink.target-database*"
value="*oracle.toplink.essentials.platform.database.SQLAnyWherePlatform*"
/>
</properties>
</persistence-unit>
</persistence>
As described earlier, when trying to create the named query, it says, there is none with that name. But it IS defied:
@XmlRootElement
@Entity
@Table(schema = "qadmin", name = "t_tl")
@IdClass(ArticlePK.class)
@NamedQuery(name = "Article.findById", query = "SELECT DISTINCT o FROM Article o WHERE o.id1 = SUBSTRING(?1, 1, LOCATE(' / ', ?1) - 1) AND o.id2 = SUBSTRING(?1, LOCATE(' / ', ?1) + 3, LENGTH(?1))")
public class Article {
@Path("/")
public final class SampleService {
protected static final EntityManagerFactory emf = Persistence.createEntityManagerFactory("X");
@GET
@Path("/sample/{id}.article")
@ProduceMime("application/article+xml")
public Response processSampleGetArticleRequest(
@PathParam("id") final String id, @Context Request request) {
final EntityManager em = SampleService.emf.createEntityManager();
try {
em.getTransaction().begin();
try {
final Article article = (Article) em.createNamedQuery("Article.findById").setParameter(1, id).getSingleResult();
Also, when not using GlassFish but standalone HttpServer from Java SE, then IT WORKS!
Pretty strange!
Thanks!
Markus
--
http://www.xing.com/go/invita/58469