比尔云BierYun--阿里云最新优惠活动
阿里云优惠码丨阿里云代金券

JPA的配置文件persistence.xml参数详解

JPA的配置文件persistence.xml参数详解http://www.bieryun.com/1892.html

  1. JPA规范要求在类路径的META-INF目录下放置persistence.xml, 文件的名称是固定的,配置模板如下:
  2. Xml代码
  3. <?xml version=“1.0” encoding=“UTF-8”?>
  4. <persistence version=“2.1”
  5.  xmlns=”<a target=_blank href=”http://xmlns.jcp.org/xml/ns/persistence”>http://xmlns.jcp.org/xml/ns/persistence</a>” xmlns:xsi=”<a target=_blank href=”http://www.w3.org/2001/XMLSchema-instance”>http://www.w3.org/2001/XMLSchema-instance</a>
  6.  xsi:schemaLocation=”<a target=_blank href=”http://xmlns.jcp.org/xml/ns/persistence”>http://xmlns.jcp.org/xml/ns/persistence</a>
  7.  <a target=_blank href=“http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd”>http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd</a>>
  8. <persistence-unit name=“persist-unit”
  9.   transaction-type=“RESOURCE_LOCAL”>
  10.   <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
  11.   <!– All persistence classes must be listed –>
  12.   <class>boa.framework.entity.CustomerEntity</class>                                                                                 <shared-cache-mode>ENABLE_SELECTIVE</shared-cache-mode>
  13.    <validation-mode>CALLBACK</validation-mode>
  14.   <properties>
  15.    <!– Provider-specific connection properties –>
  16.    <property name=“javax.persistence.jdbc.url” value=“jdbc:derby:memory:exampleDB;create=true” />
  17.    <property name=“javax.persistence.jdbc.driver” value=“org.apache.derby.jdbc.EmbeddedDriver” />
  18.    <property name=“javax.persistence.jdbc.user” value=“” />
  19.    <property name=“javax.persistence.jdbc.password” value=“” />
  20.    <property name=“javax.persistence.schema-generation.database.action”
  21.     value=“drop-and-create” />
  22.    <property name=“javax.persistence.schema-generation.create-source”
  23.     value=“script” />
  24.    <property name=“javax.persistence.schema-generation.create-script-source”
  25.     value=“META-INF/create-script.sql” />
  26.    <property name=“eclipseink.logging.level” value=“INFO” />
  27.   </properties>
  28.  </persistence-unit>
  29. </persistence>
  30. <!–
  31.       Name属性用于定义持久化单元的名字 (name必选,空值也合法);
  32.       transaction-type 指定事务类型(可选)
  33. >
  34. <persistence-unit name=“unitName” transaction-type=“JTA”>
  35.    <!– 描述信息.(可选) –>
  36.    <description> </description>
  37.    <!– javax.persistence.PersistenceProvider接口的一个实现类(可选) –>
  38.    <provider>   </provider>
  39.    <!– Jta-data-source和 non-jta-data-source用于分别指定持久化提供商使用的JTA和/或non-JTA数据源的全局JNDI名称(可选) –>
  40.    <jta-data-source>java:/test</jta-data-source>
  41.    <non-jta-data-source> </non-jta-data-source>
  42.    <!– 声明orm.xml所在位置.(可选) –>
  43.    <mapping-file>product.xml</mapping-file>
  44.    <!– 以包含persistence.xml的jar文件为基准的相对路径,添加额外的jar文件.(可选) –>
  45.    <jar-file>../lib/model.jar</jar-file>
  46.    <!– 显式列出实体类,在Java SE 环境中应该显式列出.(可选) –>
  47.    <class>boa.framework.entity.CustomerEntity</class>
  48.    <!– 声明是否扫描jar文件中标注了@Enity类加入到上下文.若不扫描,则如下:(可选) –>
  49.    <exclude-unlisted-classes>true</exclude-unlisted-classes>
  50.    shared-cache-mode
  51.   缓存模式。加了@Cacheable注解的默认为二级缓存。有四种模式:ALL-缓存所有实体;NONE-禁止缓存;ENABLE_SELECTIVE-如果加了缓存的标识,是默认的选选        项;DISABLE_SELECTIVE- enable caching unless explicitly marked as  @Cacheable(false) (not  recommended)
  52.   validation-mode
  53.   实体的验证模式,默认是激活的。当一个实体在创建、更新,在实体发送到数据库前会被进行验证。CALLBACK: entities are validated on creation, update and deletion. If no Bean Validation provider  is present, an exception is raised at initialization time.                        <!–    厂商专有属性(可选)    –>
  54.    <properties>
  55.     <!– hibernate.hbm2ddl.auto= create-drop / create / update –>
  56.       <property name=“eclipseink.logging.level” value=“INFO” />
  57.    </properties>
  58. </persistence-unit>
  59. </persistence>

 

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

强烈推荐

高性能SSD云服务器ECS抗攻击,高可用云数据库RDS