Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How Hibernate maps files

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article is about how Hibernate maps files. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.

Since JPA does not need to be configured, comments are already included in the code, so the Hibernate mapping file is attached below. in order to make the database clearer, the tables used by the two are not the same table. The table of JPA is prefixed with JPA, which is declared with @ Table.

The code to call JPA is as follows:

EntityManagerFactory emf = Persistence.createEntityManagerFactory ("TestSSH1PU2")

EntityManager em = emf.createEntityManager ()

Em.getTransaction () .begin ()

Com.hadeslee.jpaentity.Person p = new com.hadeslee.jpaentity.Person ()

P.setAge (26)

P.setName ("thousands of miles of ice")

Com.hadeslee.jpaentity.Department dept = em.find

(com.hadeslee.jpaentity.Department.class, Long.valueOf ("3"))

System.out.println ("dept= found" + dept)

Em.remove (dept)

Em.getTransaction () .commit ()

The code to call Hibernate is as follows:

Session session = HibernateUtil.getSessionFactory (). GetCurrentSession (); session.getTransaction (). Begin (); Department dept = (Department) session.load (Department.class, 2); session.delete (dept); session.getTransaction (). Commit ()

* it is found that JPA cannot be deleted, but the call on Hibernate can be deleted. At first, I thought it was the implementation of toplink, but later I deliberately changed the implementation to the implementation of Hibernate. So it is possible that JPA requires that it must be done, and that something can not be done automatically for us, which is good for safety. This may be the difference between standard and fashion.

Thank you for reading! This is the end of the article on "how Hibernate maps files". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it out for more people to see!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report