Solved

EJB with Hibernate works when tested, but not when deployed

Posted on 2010-09-18
4
652 Views
Last Modified: 2013-12-14
I am building an EJB that uses Hibernate and Netbeans as my IDE. I have written tests for all of my entities and when I run the tests, everything works great: Hibernate connects to my database and pulls data like it should. However, when I deploy to the embedded GlassFish server, I will get this error when using getNamedQuery():

org.hibernate.MappingException: Named query not known: User.getPassword

Open in new window


If I try to createQuery() using the same code as in the named query, I get:

org.hibernate.hql.ast.QuerySyntaxException: User is not mapped [SELECT u.password FROM User u WHERE u.userID = :userID]

Open in new window


And if I try using the full package name in the createQuery(), I get this:

WARNING: no persistent classes found for query class: SELECT u.password FROM com.tdocc.service.entities.User u WHERE u.userID = :userID

Open in new window



Once again, everything works great when tested and if I try to take everything and make a quick command-line application out of it, everything works perfectly. It's only when I deploy it to GlassFish. It's like GF isn't picking up any of my Entity classes.

I should also mention that GF doesn't pick up on any of the Libraries I have configured in my project. I had to manually copy all of the Hibernate libraries to GF (glassfish-3.0.1/glassfish/domain1/lib/ext) in order to get this far.

Thank you in advance for any help you can give me.
0
Comment
Question by:BNLIND
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 10

Expert Comment

by:Hegemon
ID: 33710753
Looks like your application is not fully deployed and Hibernate configuration is not being built when you deploy it. Probably packaging/deployment issue.
0
 
LVL 1

Author Comment

by:BNLIND
ID: 33711419
I'm not sure how I would go about troubleshooting or even fixing that. I am kind of new to Java and this is my first attempt at using web services. Would I be better off not using EJB, and just using a regular web service and using Tomcat or something else instead of GlassFish? I've been having nothing but problems with GF since I started using it. As I mentioned in my original post, I had to copy all of my dependencies to GF manually because it wouldn't read the jar files in the deployment. Does Tomcat have these problems too?

I am using NetBeans and I thought about trying out Apache Geronimo, but NB doesn't support Geronimo.
0
 
LVL 10

Expert Comment

by:Hegemon
ID: 33711589
The fact that you are getting errors should not affect your platform choice. If you need an application server and EJBs - use GlassFish, JBoss or any other server. If you don't need them, you can use Apache and POJOs.

I don't think there is something wrong with GlassFish, as I mentioned earlier, most likely it is a packaging or deployment problem.

If you need to supply libraries with your application, you may want to package it as a .war or .ear. When this is done properly, it is likely that the original problem will go away as well.
0
 
LVL 1

Accepted Solution

by:
BNLIND earned 0 total points
ID: 33715937
I solved the problem and confirmed that GlassFish sucks.

I took my EJB Module application and dropped it into a regular Web Application project, since my web service didn't require the enterprise stuff. Then I deployed that to GlassFish. Surprise! It didn't work at all. Same problem. Then I downloaded Tomcat, had it up and running in two minutes, deployed my application to Tomcat and it works perfectly now. I've never used Tomcat before and I had it up and running my web service in under 5 minutes and I didn't even need to manually copy all of my libraries. Tomcat read the WAR file and all the libraries inside automatically.

So if anyone else here is having the same problem, save yourself the anguish and dump GlassFish.
0

Featured Post

The Orion Papers

Are you interested in becoming an AWS Certified Solutions Architect?

Discover a new interactive way of training for the exam.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Programmer's Notepad is, one of the best free text editing tools available, simply because the developers appear to have second-guessed every weird problem or issue a programmer is likely to run into. One of these problems is selecting and deletiā€¦
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
The viewer will learn how to implement Singleton Design Pattern in Java.
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

724 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question