The persistence. xml file is to be packaged into the META-INF directory of the ejb jar file. The persistence. xml file is used to specify the data source used by the object bean and the default behavior of the entitymanager object. Persistence. the configuration of the XML file is described as follows: <persistence> <persistence-unit name = "foshanshop"> <JTA-data-source> JAVA: /defaultmysqlds </JTA-data-source> <Properties> <property name = "hibernate. hbm2ddl. auto "value =" Create-drop "/> </Properties> </persistence-unit> </persistence> one or more persistence-unit nodes, each persistence-unit node defines the persistent content name, data source used, and persistence product proprietary attributes. The name attribute defines the persistence name. The JTA-data-source node specifies the JNDI name of the data source used by the object bean.
Released on
JBoss
The data source name must contain
Java :/
PrefixThe data source name is case sensitive. The properties node is used to specify the attributes of the persistence product,
Different application servers use different persistence products.For example
JBoss
Use
Hibernate
,
Weblogic10
Use
Kodo
,
Glassfish/Sun Application Server/oralce
Use
Toplink. Because JBoss uses hibernate, Hibernate has a property. hbm2ddl. auto: Specifies whether to synchronize the database structure when the entity bean is released. If hibernate. hbm2ddl. the value of auto is set to create-drop. The corresponding database table is automatically created and deleted when the entity bean is released and detached (note: when the JBoss server is started or shut down, the release and uninstallation of the Entity Bean will also be triggered ). The toplink. DDL-generation attribute of the toplink product also plays the same role.
TIPS: If your table already exists and you want to retain data, you can use hibernate to publish the object bean. hbm2ddl. auto is set to none or update. We recommend that you use update to update the data table for future changes to the object bean. In this way, the corresponding fields can be added to the data table when an attribute is added to the object bean.