Hi,
I am writing this post regarding JSF/Eclipselink JPA using netbeans, although, it is logical and straight forward in netbeans website, but it still has some pitfalls need to be pointed out (and I spent the last two days in one of them although I knew it before).
Let us start demonstrating with simple example in netbeans. In order to create the below example, you need prerequisites
I am writing this post regarding JSF/Eclipselink JPA using netbeans, although, it is logical and straight forward in netbeans website, but it still has some pitfalls need to be pointed out (and I spent the last two days in one of them although I knew it before).
Let us start demonstrating with simple example in netbeans. In order to create the below example, you need prerequisites
- Postgressql jdbc driver as I'm using postgres database
- Database connection from service tab
- Jeddict plugin for database modelling(add this to netbeans from tools->plugins->downloaded->add plugins)
Now to the example
- create new web application choosing glassfish as your application server and JSF framework
- create jdbc connection pool and jdbc resource such as jdbc/example JNDI
- using jeddict create Jpa Modeler
- drag and drop entities
- put the required names, attributes and relationships
- go to the project and create a persistence unit selecting the JNDI you created earlier
- copy the persistence unit name to the properties of the diagram and save
- right click on the Jpa Modeler screen and click on Generate Source Code, then put entity in the Package name then click on Generate
- right click on the project and JSF Pages from Entity Classes, name Session Bean Package facade and JSF Classes Package entity.domain
- Now you will have all the controllers/Managed Beans and EJBs/Session Beans in addition to the entities which were created already in the previous step, in addition to the jsf pages for all the entities CRUD operations
- NOW, pay attention to the pitfalls so you application works correctly,
- all entities will not be serializable by default neither have (no argument constructor) nor (equals and hashcode functions), WHICH are must in order to have your application works properly.
Optional, when you create the departments and navigate to employees to create employee, you will find drop down list looks like the snapshot, and you can rectify this using toString() in the respective entity which is Department here
Troubleshooting few issues:
- Sometime the application doesn't work properly if you have already created tables with the same name but not the same attributes before, and you can fix it by making the persistence as Drop and Create, then Clean and Compile and Run. DON'T forget to return the persistence back it to Create.
- Sometimes you face issue of "Unreachable, identifier 'departmentController' resolved to null" for example which can be solved by restarting the glassfish.