In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article shows you how to analyze Java applications and Hibernate, the content is concise and easy to understand, can definitely make your eyes bright, through the detailed introduction of this article, I hope you can learn something.
Hibernate has a lot to learn. Here we focus on Java applications and Hibernate, including org.hibernate.Session as the primary runtime interface.
The Java application integrates mapping files, properties files for data persistence. First copy the Catalog.hbm.xml and hibernate.properties files to the same directory. And add this directory to CLASSPATH. Use import to import the org. Hibernate and dom4j packages in your Java application.
Org.hibernate.Session is the primary runtime interface that connects Java applications to Hibernate. You can use it to add, get, update, and delete XML data from database tables. We can get a Session object from a SessionFactory. This SessionFactory interface provides openSession methods for creating a database connection and opening a connection session. The org.hibernate.cfg.Configuration class is used to specify configuration properties and to create a mapping file for SessionFactory. The following code creates a configuration object:
Configuration config=new Configuration ()
The following code adds the mapping file catalog.hbm.xml to the configuration:
Config.addFile ("catalog.hbm.xml")
Now the mapping file Catalog.hbm.xml and the JDBC properties file are in the same directory, and the application uses the configuration object to get the information about this file. The following code creates a SessionFactory object:
SessionFactory sessionFactory=config.buildSessioFactory ()
Next, you will add data to the data table created using the SchemaExport tool, starting with a Session object from the SessionFactory object:
Session sess = sessionFactory.openSession ()
The following code will get a Transaction object that we can use to add data to the data table:
Org.hibernate.Transaction tx = sess.beginTransaction ()
Start a session using DOM4J mode, and the second session has the same connection, transaction, and context properties as the * primary session:
Session dom4jSession = session.getSession (EntityMode.DOM4J)
Next, you will create a SAXReader object to analyze the XML document that describes the data table. We can use the read (File) method to analyze the catalog.xml file as follows:
SAXReader saxReader = new SAXReader (); Document document = saxReader.read (new File ("c:/Hibernate/catalog.xml"))
The following code gets a list of catalog nodes in the document object and creates an Iterator object to browse the list abort data:
List list = document.selectNodes ("/ / catalog"); Iterator iter = list.iterator ()
Iterate can enumerate the objects in the list and get the corresponding nodes from the list. We can use the save (String entityName,Object object) method to save the node data in the database. The Java application and Hibernate are described above.
The above is how to analyze Java applications and Hibernate. Have you learned any knowledge or skills? If you want to learn more skills or enrich your knowledge reserve, you are welcome to follow the industry information channel.
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.