Solved

EJB with Hibernate works when tested, but not when deployed

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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Jaspersoft Studio is a plugin for Eclipse that lets you create reports from a datasource.  In this article, we'll go over creating a report from a default template and setting up a datasource that connects to your database.
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
The viewer will learn how to implement Singleton Design Pattern in Java.

757 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now