简体   繁体   中英

How do I setup a project in Eclipse for JSP, Servlet, JPA, Hibernate web development

I am a newbie to Hibernate.

I have a school project using MySQL, JDBC, JSP/Servlet, Tomcat technologies.

The way that I do the database connection in EVERY Servlet is:

  1. establish database connection in JDBC.
  2. create Query statement and execute it.
  3. close database connection.

That is very very tedious, so I want to use JPA with Hibernate to handle it.

I looked some tutorials and saw that there's a JPA Project option in Eclipse, so went ahead and used it.

Now I am confused about how to add JSP/Servlet into this project. It seems like this type project is not meant for handling any front-end technologies.

Could anyone please help me clear this out? What type of eclipse project should I use in my case?

Thanks a lot.

You can use whatever Eclipse project templates you want, they just setup directory structure and libraries for convenience. You could start with a normal Java project if you wanted, it's just a matter of understanding what libraries/dependencies to setup. My personal preference is to use the Dynamic Web Project so it set's up my web directory structure and web.xml.

Adding JPA/Hibernate to a project consists of:

1) Mapping your classes (annotations or xml)
2) Creating the EntityManagerFactory/SessionFactory
3) Inject the Factory where you need database access

If this is your first non-trivial database application take a look at the DAO Pattern . It will help you understand how to abstract away database specific decisions (eg JDBC vs Hibernate vs JPA) from your application logic.

Not sure what tutorial and information you have looked at. There are good information that is available, but to start you can take a quick look some myeclipse tutorials here and the one's up here are good . Cheers.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM