Win a copy of Cloud Native PatternsE this week in the Cloud forum
or Natural Language Processing in the AI/ML 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
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Knute Snortum
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Piet Souris
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

JPA Pro 2 chapter 3 employeeService

 
Ranch Hand
Posts: 1742
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 Hand
Posts: 1742
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 Hand
Posts: 1742
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:
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!