Skip to main content

Please help me with integrating javax.persistence into GlassFish

14 replies [Last post]
recursion
Offline
Joined: 2008-07-12

Hello guys,
I'm completely new to Java Enterprise Environment and concepts. I have an installation of the GlassFish server and am trying to compile a simple web application using JPA. The problem is that i receive the error "package javax.persistence does not exist". I searched this isuue over the internet and couldn't found any solution.
I downloaded and did everything specified in "https://glassfish.dev.java.net/downloads/persistence/JavaPersistence.html"
but nothing changed. I have the JPA jars in my "GlassFish"/lib folder.

I am using the NetBeans IDE 6.1 and searched its Help for some help. It seems that i have done everythin necessary! I have included the persistence jars in the library node of my project! Still i get "package javax.persistence does not exist".
Pleeeeeeeeease HELP! :)))

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
poluris82
Offline
Joined: 2008-11-07

Had the same issue as recursion and after a long trial and error and search, stumbled upon this thread. I opened required projects and added the TopLink Essentials library and it compiled like a charm. Thanks a lot for your ideas.

recursion
Offline
Joined: 2008-07-12

Problem solved! I added the "import javax.annotation.*" statement and the project compiled perfectly. Obviously the Entity, Id, Table and all other annotations require the annotation package.....
Thank you for your ideas! :)

Message was edited by: recursion

kororos
Offline
Joined: 2008-11-16

The strange problem is that when I use the auto-complete feature of NetBeans IDE, the javax.persistence does not appear. This is as if it does not find in the classpath the javax.persistence (and a lot more) package. Please take a look at the following picture.

Note: If I create a new web project, with the same app server, it works fine. I believe that this is maybe a bug in the setup of the bookstore1 project. I understand that importing javax.annotation.* solves the problem, but I believe that it is a workaround and not the solution.

[b]This is REALLY STRANGE:[/b] I was trying it out again, to get the screenshot, but I had delete the examples, downloaded again and tried in the IDE. Now it did not happen. [b]Very strange[/b].

recursion
Offline
Joined: 2008-07-12

Thank you guys for your time! But unfortunately both of you are incorrect.

First try: i removed the "import javax.persistence.*;" statement and replaced all occurrencies of the Entity, Table and Id annotations with the full names, i.e. javax.persistence.Entity, but the project didn't compile. I get the same error "package javax.persistence does not exist"

Second try: I opened all the required project (this is only the bookstore project). It already had the Toplink Essentials package included in its Library section. I compiled, and nothing happened. Here's the screenshot:

http://img140.imageshack.us/my.php?image=jpaproblemri7.jpg

However, keep trying and giving good ideas! :) Maybe it will work some day....

recursion
Offline
Joined: 2008-07-12

Well, thank you for your effort, but no. This is not the problem! I have already tried this option without any success. Take a look:

http://img172.imageshack.us/my.php?image=jpaproblemjy2.jpg

jmarine
Offline
Joined: 2006-09-24

Hi,

It seems that "bookstore1" project (web application), is importing the "dist/bookstore.jar" from another project (persistence unit?). In this case, NetBeans will also try to recompile the project's dependencies (other projects that may also require "TopLink Essential" library in the compiler's CLASSPATH).

I think you should open the other project (manually or right click the web project, and select "open required projects" option), and edit its properties to also add the "TopLink Essentials" library to the compile-time libraries (in the "libraries" category).

adamman71
Offline
Joined: 2007-01-31

Hi jmarine,

I had exactly the same problem as described at the beginning of this thread for the same example. I did two things:

a) I created the build.properties file as described in http://java.sun.com/javaee/5/docs/tutorial/doc/bnaan.html. This is a necessary step described in the documentation. Then I opened the bookstore1 project without its dependencies and tried to compile it. That's when I got the javax.persistence does not exist message. Adding TopLink Essential did not solve the issue.

b) Then, I followed your recommendations and opened the bookstore project. I made sure that the TopLink Essential library was included in both projects. Now it compiles fine!!!

Thanks for everyone's input,

J.

recursion
Offline
Joined: 2008-07-12
jmarine
Offline
Joined: 2006-09-24

Hi,

I think you forgot to add "TopLink Essentials" JARs to the compiler's CLASSPATH. With NetBeans 6.1, you can right click on the "bookstore1" project, select "Properties" option, then select the "libraries" category, press the "add library" button and select the "TopLink Essentials" library.

Note: you can also uncheck the "package" option if you want to deploy the project to a GlassFish application server, because it already contains this JPA provider.

srmcatee
Offline
Joined: 2008-07-13

The problem is more than just the library.

I have noticed any library I add will not work through the import statement. For example:

My code looks like the following:

import net.sf.jasperreports.engine;

private void jButton1MouseClicked(java.awt.event.MouseEvent evt) {
// TODO add your handling code here:

try {
String reportName = "mystuff.jasper";

InputStream fis = this.getClass().getClassLoader().getResourceAsStream(reportName);

JasperPrint print = JasperFillManager.fillReport(fis, new HashMap(), new JREmptyDataSource());
}
catch (Exception ex)
{
ex.printStackTrace();
}
}

The Netbeans 6.1 IDE tells me on the import line that net.sf.jasperreports does not exist. However, if I comment out the import line and fully qualify the reference to the libarary it compiles. For example:

try {
String reportName = "myreport.jasper";

InputStream fis = this.getClass().getClassLoader().getResourceAsStream(reportName);

net.sf.jasperreports.engine.JasperPrint print = net.sf.jasperreports.engine.JasperFillManager.fillReport(fis, new java.util.HashMap(), new net.sf.jasperreports.engine.JREmptyDataSource());
}
catch (Exception ex)
{
ex.printStackTrace();
}
}

This is all after I have gone to the properties of the project and added the JasperReport Library.

I think it is a bug in the IDE. Netbeans, any comments?

Markus KARG

I do not see what that has to do with GlassFish.

Despite this possibly subjective feeling, I would think that you forgot
to tell your IDE that your project shall use JasperReports on its classpath.

Regards
Markus

glassfish@javadesktop.org schrieb:
> The problem is more than just the library.
>
> I have noticed any library I add will not work through the import statement. For example:
>
> My code looks like the following:
>
> import net.sf.jasperreports.engine;
>
> private void jButton1MouseClicked(java.awt.event.MouseEvent evt) {
> // TODO add your handling code here:
>
> try {
> String reportName = "mystuff.jasper";
>
> InputStream fis = this.getClass().getClassLoader().getResourceAsStream(reportName);
>
> JasperPrint print = JasperFillManager.fillReport(fis, new HashMap(), new JREmptyDataSource());
> }
> catch (Exception ex)
> {
> ex.printStackTrace();
> }
> }
>
>
> The Netbeans 6.1 IDE tells me on the import line that net.sf.jasperreports does not exist. However, if I comment out the import line and fully qualify the reference to the libarary it compiles. For example:
>
> try {
> String reportName = "myreport.jasper";
>
> InputStream fis = this.getClass().getClassLoader().getResourceAsStream(reportName);
>
> net.sf.jasperreports.engine.JasperPrint print = net.sf.jasperreports.engine.JasperFillManager.fillReport(fis, new java.util.HashMap(), new net.sf.jasperreports.engine.JREmptyDataSource());
> }
> catch (Exception ex)
> {
> ex.printStackTrace();
> }
> }
>
> This is all after I have gone to the properties of the project and added the JasperReport Library.
>
> I think it is a bug in the IDE. Netbeans, any comments?
> [Message sent by forum member 'srmcatee' (srmcatee)]
>
> http://forums.java.net/jive/thread.jspa?messageID=286286
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@glassfish.dev.java.net
> For additional commands, e-mail: users-help@glassfish.dev.java.net
>
>

--
http://www.xing.com/go/invita/58469

[smime.p7s]

recursion
Offline
Joined: 2008-07-12

Thank you Markus for your answer! I am not a beginner with Java, but i have only Java SE background, so i am new to the Java EE world. I started a job as a developer and was given the task to gain some initital experience in JPA. So i am a beginner with JPA and NetBeans.
I found out that the default implementation of JPA in GlassFish was provided by TopLink Essentials (through the 2 jars that you mentioned). I am trying to compile and run a simple web application which i got as an example from the official Sun Java EE 5 tutorial. So i suppose that it is the second case. However, both jars are present in the libraries imports in my app, so it should know that they exist and where to find them.
The problem is that my application cannot compile and the error i get is "package javax.persistence does not exist" which is caused by the import statement - import javax.persistence.*;

You say:

"or are you using TopLink inside of an enterprise application (ejb-jar file or
war file), then you just need the persistence.xml in either META-INF or
WEB-INF/classes/META-INF."

Going back to the file system i can see that the persistence.xml file is present in the META-INF directory. So it seems that this is all right too. Through the NetBeans IDE, project explorer, I can only see the WEB-INF section from all that you mention. I put the persistence.xml file in it (just in case) and compiled, but nothing changed. What seems to be the problem ?

recursion
Offline
Joined: 2008-07-12

Please give me some hint! I am stuck at this place and cannot move ahead towards learning JPA! :( I did everything and still it doesn't work. I added every possible path (related to JPA) to my path environment variable. So this is not the reason. NetBeans shows that there is a Library called "Toplink Essentials", which has its jars present in the netbeans folder, and i have imported this library in my project! Inside there is the javax.persistence package!

Please help me :((

Markus KARG

Please describe what your problem is (error messages etc.), so we can
help you. From what you wrote below it is hard to detect where exactly
you are stuck. Are you a beginner with JPA or a beginner with Java or a
beginner with NetBeans? Is your problem that you cannot compile or that
you cannot run?

Are you using TopLink inside of a standalone JAR (then
toplink-essentials.jar and toplink-essentials-agent.jar and
META-INF/persistence.xml must be on your classpath at runtime), or are
you using TopLink inside of an enterprise application (ejb-jar file or
war file), then you just need the persistence.xml in either META-INF or
WEB-INF/classes/META-INF.

Regards
Markus

glassfish@javadesktop.org schrieb:
> Please give me some hint! I am stuck at this place and cannot move ahead towards learning JPA! :( I did everything and still it doesn't work. I added every possible path (related to JPA) to my path environment variable. So this is not the reason. NetBeans shows that there is a Library called "Toplink Essentials", which has its jars present in the netbeans folder, and i have imported this library in my project! Inside there is the javax.persistence package!
>
> Please help me :((
> [Message sent by forum member 'recursion' (recursion)]
>
> http://forums.java.net/jive/thread.jspa?messageID=286193
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@glassfish.dev.java.net
> For additional commands, e-mail: users-help@glassfish.dev.java.net
>
>

--
http://www.xing.com/go/invita/58469

[smime.p7s]