In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-03 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
Xiaobian to share with you how Hibernate initialization, I believe most people do not know how, so share this article for everyone's reference, I hope you have a lot of harvest after reading this article, let's go to understand it together!
Hibernate has two configuration file formats, XML (hibernate.cfg.xml by default) and properties (Hibernate. properties by default). Different configuration files have different initialization methods for Hibernate
For example, if the properties file is used as a configuration file, then Hibernate initialization code is roughly
Configuration config = new Configuration(); config.addClass(myclass.class);
If the configuration file is XML,
Configuration config = new Configuration().config();
Configuration files in XML file format do not support addClass method!!! This is because the Mpaaing file is already defined in the configuration XML file, so there is no need to import the POJO file encoded.
Another: many articles on the Internet, and even some books say that Hibenate configuration files must be placed in the root directory of the class, refer to the API, found that this statement is incorrect, such as Configuration config = new Configuration().config(configuration file name); completely OK.
All config methods are as follows:
addCacheableFile(File xmlFile)
If a cached xmlFile + ".bin" exists and is newer than xmlFile the ".
bin" file will be read directly.
Configuration addClass(Class persistentClass)
Read a mapping from an application resource, using a convention.
Configuration addDirectory(File dir)
Read all mapping documents from a directory tree.
Configuration addDocument(org.w3c.dom.Document doc)
Read mappings from a DOM Document
Configuration addFile(File xmlFile)
Read mappings from a particular XML file
Configuration addFile(String xmlFile)
Read mappings from a particular XML file
void addFilterDefinition(FilterDefinition definition)
Configuration addInputStream(InputStream xmlInputStream)
Read mappings from an InputStream
Configuration addJar(File jar)
Read all mappings from a jar file
Configuration addProperties(Properties extraProperties)
Set the given properties
Configuration addResource(String path)
Read mappings from an application resource trying different classloaders.
Configuration addResource(String path, ClassLoader classLoader)
Read mappings from an application resource
Configuration addURL(URL url)
Read mappings from a URL
Configuration addXML(String xml)
Read mappings from a String
That's all for Hibernate initialization, thanks for reading! I believe that everyone has a certain understanding, hope to share the content to help everyone, if you still want to learn more knowledge, welcome to pay attention to 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.