Hi,
I have written a velocity template that I would like to contribute to MyEclipse. It generates a "SLHSB" (Stateless Hibernate Session Bean) per entity type / database table, eg for "customer" entities (in the customer table) there will be a CustomerServiceBean that provides all CRUD operations (saveOrUpdate, delete, findById, findByExample, findAll) required for most applications.
Using these methods, you can design your master/detail views without having to write one single line of EJB code - just use CustomerService.findAll() in the /customerList.do action, CustomerService.findById() in the /customerDetail.do action, CustomerService.findByExample() in the /customerSearch.do action, and CustomerService.saveOrUpdate() or CustomerService.delete() in the /customerDetail.do?action=edit action.
An example of a SLHSB can be seen here:
http://www.studenter.hb.se/~arch/KontaktServiceBean.java.html
In fact, if this template could be called from eg the MyEclipse database explorer, the required steps to build a complete J2EE multi layered application could be reduced to
1. Design the database [manual]
2. Generate the middle layer (business objects /w Hibernate mappings + session beans) [automatic]
3. Design the user interface [manual]
This equals only two manual steps, and could really reduce the time from idea to finished application.
Now, this template will not be called by MyEclipse just by adding it in the plugins\com.genuitec.eclipse.hibernate_3.8.3\templates directory as I assume that the various templates are called explicitly by MyEclipse. I have tried to rename my template to say, mappedobject.vm to "trick" MyEclipse into using it, but as it does not generate the same file as the original template the generation fails.
Also, the user should be able to define the JNDI url of the SessionFactory used by the generated beans (see example for usage) so I kindly suggest that you (if you decide to implement this template) add a wizard where the user can define the value of this URL (suggestably: java:/[project name]/SessionFactory or java:/[database schema]/SessionFactory).
Related:
- For JBoss, you could add a Hibernate SAR/MBean module wizard that generates the SessionFactory configuration (see thread
http://www.myeclipseide.com/PNphpBB2+file-viewtopic-t-4653.html)
as the first step, and the business objects + hibernate mappings as a second step. Ideally, this session factory config should be managed by MyEclipse so that the user could browse for and choose session factory when running the SLHSB wizard.
Summary:
If you like this idea, I suggest that you add a "Stateless Hibernate Session Bean" wizard that could be launched either/or from File->New..->J2EE->EJB and the popup menu of a table(connection?) in the database explorer perspective.
Did I forget anything...umm...oh, yeah the template itself can be found here:
http://www.studenter.hb.se/~arch/slhsb.vm
Will MyEclipse be known for "the fastest J2EE development method ever"? I hope so. Regardless if, the development time of a many J2EE projects could be greatly reduced anyhow.
Hope you like the idea.
Regards,
Mikael.