In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces how to solve the problem of modifying the storage path of persistence.xml configuration files, which is very detailed and has a certain reference value. Interested friends must finish reading it!
Modify the storage path of persistence.xml configuration file
The following problems are encountered when integrating Spring, struts2 and Spring Data JPA, which are now recorded for reference.
Configuring the entity management factory according to the above code will throw an exception to the effect that the persistence.xml file cannot be found.
Because my persistence.xml file is placed in the resource folder at the same level as src, and by default the configuration file is loaded in the META-INF folder under src.
There are two solutions.
1. The first kind:
Move the persistence.xml file under src/META-INF/, or create it manually if the folder does not exist
2. The second kind:
Org.springframework.orm.jpa.LocalEntityManagerFactoryBean
Change to
Org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean
If you want to understand the principle of implementation, please check the source code for yourself.
Persist persistence.xml profile
In EJB, an entity Bean application consists of entity classes and persistence.xml files. The persistence.xml file is in the META-INF directory of the jar file. The persistence.xml file specifies the data source used by the entity Bean and the default behavior of the Entity Manager object.
Let's take a look at the simplest persistence.xml file and see how it is configured.
Java:/DefaultMySqlDS
Persistence-unit: there can be one or more nodes, and each persistence-unit node defines the persistent content name, the data source used, and the proprietary attributes of the persistent product.
Name: attribute definition persistent name.
Jta-data-source: the node specifies the JNDI name of the data source used by the entity Bean. If the application is published under jboss, the data source name must be prefixed with java:/. The data source name is case sensitive.
Properties: the node is used to specify the attributes of the persistent product.
For properties nodes, it is important to note that each application server uses different persistence products, such as jboss using hibernate,weblogic10 and kodo. Because jboss uses hibernate,hibernate has an attribute "hibernate.hbm2ddl.auto", this attribute specifies whether the entity Bean publishes the database structure synchronously. If the value of "hibernate.hbm2ddl.auto" is set to "create-drop", the corresponding database tables will be automatically created and deleted when the entity is published and uninstalled.
The release and uninstallation of entity Bean is also triggered when the jboss server is started or shut down.
Ps: if your table already exists and you want to keep the data, you can set the value of hibernate.hbm2ddl.auto to none or update when publishing entity bean, and later to reflect the changes of entity bean to the data table, it is recommended to use update, so that entity Bean can add corresponding fields to the data table at the same time when adding an attribute.
Expansion (persistence-unit)
The persistence unit contains the following properties:
Entity classes within the scope (scope) of the persistence unit
A persistence provider (Persistence Provider) or library that provides persistence for entity classes
Data source for entity classes (Data Source)
Type of transaction used by the application (Transaction Type)
Persistence units can be packaged into WAR files, EJB-JAR files, part of EAR files, or directly packaged into JAR files that the application can use directly.
The scope (scope) of the persistence unit depends on the location of the persistence.xml file. In general, IDE can use the boot interface to position the persistence.xml correctly. For example, using IDE to create a persistence unit for the EJB module (Module), the persistence.xml file will be placed in the src/conf directory of the EJB module, and when you package the module, the persistence.xml file will be placed in the META-INF directory of the EJB JAR file. So the scope of the persistence unit is the class in the EJB JAR file.
The location of the ps:persistence.xml file determines the root of persistence (Persistence Root). The root of the persistence is the JAR file or the directory that contains the META-INF directory (provided persistence.xml is here).
The above is all the contents of this article entitled "how to solve the problem of changing the storage path of persistence.xml configuration files". Thank you for reading! Hope to share the content to help you, more related knowledge, 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: 219
*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.