I know it's pretty outdated technology but I found myself in the need of doing a project using Jakarta EE on GlassFish. I already know the answer, I just want to document my workaround for making this combination of technologies work together, since the information to fix all the problems that may arise is scattered through many different posts and websites.
First I will list the issues and then I will reply with the solutions:
First problem I encountered is that IntelliJ asks you to pay a subscription in order to use Jakarta EE functionality and Eclipse IDE has archived their plugins for GlassFish, so I ended up using Netbeans because it's the only IDE that still supports GlassFish apparently.
Then, after downloading Apache Derby (10.16.1.1) for setting up the database server I was receiving this exception:
An error occurred while creating the database:
java.lang.ClassNotFoundException: org.apache.derby.jdbc.Clientdriver
- After solving the missing class issue, every commit I tried to do to the database was being set to rollback, being unable to persist anything into the database. This is the exception I was getting:
javax.persistence.RollbackException: Transaction "rolled back" because transaction was set to RollbackOnly.
- Finally, when the transaction was finally not getting rolled back, I was getting an error because apparently the table I was trying to write into didn't exist. Even though I could clearly see it in the Derby server and the
persistence.xmlfile pointed to it correctly:
java.sql.SQLSyntaxErrorException: Table/View 'CUSTOMER' does not exist.
Here's the workaround that I used to solve all these issues:
Basically the library had a class in the wrong package. I just copied the
jdbcfolder located indb-derby-10.16.1.1-bin\lib\derbytools.jar\org\apache\derbyand pasted it indb-derby-10.16.1.1-bin\lib\derbyclient.jar\org\apache\derby.Here the problem was that when the
persistence.xmlfile was created, instead of using the jakarta library for the persistence-unit properties, it was using the old javax library, creating an incompatibility. Change all thejavaxforjakarta. Also, you may need to set thetransaction-typetoJTA.This is the one that took me more time, I was just going crazy. In the
persistence.xmlfile we stated which database we want to connect to. However, there's a file calleddomain.xmlinside the GlassFish server domain'sdomain-name\configfolder which also sets up a database connection and dominates over the persistence file. It stablishes a connection to three different databases, we have to change the one namedDerbyPool:And that's it! If you installed everything correctly and fixed these issues your GlassFish + Derby server should be running and synchronized with Netbeans and all queries to the database should be working properly.