NetBeans Forums

 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
  

javaee tutorial: i'm stuck!

 
Post new topic   Reply to topic    NetBeans Forums -> Java EE Users
View previous topic :: View next topic  
Author Message
Khaoz



Joined: 01 Sep 2008
Posts: 6

PostPosted: Tue Oct 07, 2008 1:29 am    Post subject: javaee tutorial: i'm stuck! Reply with quote

I'm trygin to do the steps described here:

http://java.sun.com/javaee/5/docs/tutorial/doc/bnaff.html

To deploy the bookstore1 application, but:

Code:

init:
deps-module-jar:
init:
deps-jar:
Compiling 11 source files to /home/khaoz/projetos/java/javaeetutorial5/examples/web/bookstore/build/classes
/home/khaoz/projetos/java/javaeetutorial5/examples/web/bookstore/src/com/sun/bookstore/database/Book.java:13: package javax.persistence does not exist
import javax.persistence.Entity;
/home/khaoz/projetos/java/javaeetutorial5/examples/web/bookstore/src/com/sun/bookstore/database/Book.java:14: package javax.persistence does not exist
import javax.persistence.Id;
/home/khaoz/projetos/java/javaeetutorial5/examples/web/bookstore/src/com/sun/bookstore/database/Book.java:15: package javax.persistence does not exist
import javax.persistence.Table;
/home/khaoz/projetos/java/javaeetutorial5/examples/web/bookstore/src/com/sun/bookstore/database/Book.java:18: cannot find symbol
symbol: class Entity
@Entity
/home/khaoz/projetos/java/javaeetutorial5/examples/web/bookstore/src/com/sun/bookstore/database/Book.java:19: cannot find symbol
symbol: class Table
@Table(name = "WEB_BOOKSTORE_BOOKS")
/home/khaoz/projetos/java/javaeetutorial5/examples/web/bookstore/src/com/sun/bookstore/database/Book.java:55: cannot find symbol
symbol  : class Id
location: class com.sun.bookstore.database.Book
    @Id
6 errors
BUILD FAILED (total time: 0 seconds)


You will say that i'm need to add TopLink essentianls. I have made this without success.

Under Libraries in bookstore1 project i have:

bookstore - dist/bookstore.jar
JDK 1.6 (Default)
GlassFish V2

Under GlassFish V2 a javaee.jar exists wich also contains a javax.persistence package.
Back to top
Khaoz



Joined: 01 Sep 2008
Posts: 6

PostPosted: Tue Oct 07, 2008 2:27 am    Post subject: Reply with quote

If i use

ant && ant deploy

Everything build and deploy without problems... Shocked
Back to top
pmanop



Joined: 15 Feb 2009
Posts: 1

PostPosted: Sun Feb 15, 2009 5:11 am    Post subject: Reply with quote

I found the solution.

Quote:
http://osdir.com/answers/java/16634-java-ee-programming-javax-persistence-not-found.html
Back to top
robertgp



Joined: 20 Jul 2009
Posts: 1

PostPosted: Mon Jul 20, 2009 1:43 pm    Post subject: How to set up NetBeans and GlassFish for bookstore1 Reply with quote

I just solved this problem. I decided to join the forum and share the solution with everybody.

Let's go!

Right-click the "bookstore1" project in the Projects tab and click the option "Open Required Projects". The project "bookstore" will be opened. Build the "bookstore" project. If that didn't turn out, add TopLink Essential Libraries (they were included in my case). Then, build and deploy "bookstore1" project. It should work.

The next problem you may have to deal with, is setting up the DB connections. This doesn't have to do with the message but I think it may be useful for you.

Setting up the DB

- Go to the "Services" Tab.
- Make sure GlassFish V2 is started.
- Click "Databases", and right-click "Java DB".
- Select "Create Database"
- Introduce a Database Name ("BookDB", e.g.) and a UserName and Password (whatever you want)
- Refresh the "Databases" (right-click, Refresh)
- Right-click the Database you just created
- Select "Execute command..."
- Paste "tutorial.sql" contents and execute the script

Setting up Connection Pool and JDBC Resource

- Go to the Admin Console of GlassFish (http://localhost:4848)
- Log in (generally: admin / adminadmin)
- Go to: Resources --> JDBC --> Connection Pools
- Create a New One (e.g. TutorialPool)
- Resource Type: javax.sql.DataSource
- Properties (ServerName: localhost; PortNumber: 1527; User: the one you introduced; Password: the one you introduced; DatabaseName: BookDB)
- You can PING the DB and check if the connection pool is correctly set up
- Go to: Resources --> JDBC --> JDBC Resources
- Create a New One with the name "jdbc/BookDB" use the TutorialPool you created.

Setting up the persistence.xml file

- Go to "bookstore" (NOT bookstore1) Project
- Go to Source Packages --> META-INF --> persistence.xml

This worked for me:

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="1.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd">
<persistence-unit name="book" transaction-type="JTA">
<provider>oracle.toplink.essentials.PersistenceProvider</provider>
<jta-data-source>jdbc/BookDB</jta-data-source>
<class>com.sun.bookstore.database.Book</class>
</persistence-unit>
</persistence>


I expect this is useful for you. Sorry for my crummy English.

Greetings,

Robert
Back to top
tomFinegan



Joined: 22 Jul 2009
Posts: 1

PostPosted: Wed Jul 22, 2009 9:27 pm    Post subject: Reply with quote

Thank you, Robert. I also was stuck.

I would like to add a couple points:

In the NetBeans Services Tab -
Call your database "bookDB", so it matches some hard-coding in the servlets. I don't know if this is critical, but this way does work.

In the persistence.xml -
Be careful to match the data source exactly to what you see in the JDBC Resources on your server admin page. If it is "bookDB" and NOT "jdbc/bookDB" you should follow suit in persistence.xml

<jta-data-source>bookDB</jta-data-source>

Press on!
Back to top
Display posts from previous:   
Post new topic   Reply to topic    NetBeans Forums -> Java EE Users All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum


Powered by phpBB
By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2012, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo