Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 655
  • Last Modified:

EJB with Hibernate works when tested, but not when deployed

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
BNLIND
Asked:
BNLIND
  • 2
  • 2
1 Solution
 
HegemonCommented:
Looks like your application is not fully deployed and Hibernate configuration is not being built when you deploy it. Probably packaging/deployment issue.
0
 
BNLINDAuthor Commented:
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
 
HegemonCommented:
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
 
BNLINDAuthor Commented:
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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now