Solved

EJB with Hibernate works when tested, but not when deployed

Posted on 2010-09-18
4
647 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
  • 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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Weekend adv creator 3 38
Windows 10 IE Certificate Issue 10 45
pagenation logic how it is working in my code 1 29
going to wrong jsp page 2 20
How to install Selenium IDE and loops for quick automated testing. Get Selenium IDE from http://seleniumhq.org Go to that link and select download selenium in the right hand columnThat will then direct you to their download page.From that page s…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
The viewer will learn how to use and create new code templates in NetBeans IDE 8.0 for Windows.

770 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