This week's book giveaway is in the Java in General forum.
We're giving away four copies of 97 Things Every Java Programmer Should Know and have Kevlin Henney & Trisha Gee on-line!
See this thread for details.
Win a copy of 97 Things Every Java Programmer Should Know this week in the Java in General forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

JPA Pro 2 chapter 3 employeeService

 
Ranch Foreman
Posts: 1897
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I updated the original persistence.xml into:

These values are specified to mySQL and I have a database called myTest.

The original persistence.xml provided is:

This may not be applicable to those who don't use Derby database.
And also, the Employee.java should implement Serializable:


And you may want to follow my file structure in Eclispe. See the diagram below.

Create a folder META-INF  under src and put persistence.xml there.
Include eclispelink.jar, javax.persistence...java and mysql-connector-...java in the classpath.

I hope this help.
fileStructure.JPG
[Thumbnail for fileStructure.JPG]
 
Himai Minh
Ranch Foreman
Posts: 1897
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One more notes, the persistence.xml should be :

Reference:
http://www.javaxt.com/Tutorials/Glassfish/How_to_set_up_a_Connection_Pool
https://dzone.com/articles/connection-pooling-glassfish-nb
https://computingat40s.wordpress.com/how-to-setup-a-jdbc-connection-in-glassfish/
 
Himai Minh
Ranch Foreman
Posts: 1897
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If we don't specify <jta-data-source>, we cannot use @PersistenceContext(unitName="EmployeeService") in the EmployeeService.java.

If we don't have <jta-data-source>, we should do this:
 
I will open the floodgates of his own worst nightmare! All in a tiny ad:
Devious Experiments for a Truly Passive Greenhouse!
https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
    Bookmark Topic Watch Topic
  • New Topic