java - What's the meaning of properties of persistence.xml file -


i'm studying hibernate framework, , know can information de properties need include in file persistence.xml

i search propertie provider, don't specific information, sombody me :d

<persistence xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xsi:schemalocation="http://java.sun.com/xml/ns/persistence  http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd" version="2.0"> <persistence-unit name="tarefas">     <!-- provedor/implementacao jpa -->     <provider>org.hibernate.ejb.hibernatepersistence</provider>     <!-- entidade mapeada -->     <properties>         <!-- dados da conexao -->         <property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.driver" />         <property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/jpa" />         <property name="javax.persistence.jdbc.user" value="root" />         <property name="javax.persistence.jdbc.password" value="root" />         <!-- propriedades hibernate -->         <property name="hibernate.dialect" value="org.hibernate.dialect.mysql5innodbdialect" />         <property name="hibernate.show_sql" value="true" />         <property name="hibernate.format_sql" value="true" />         <!-- atualiza o banco, gera tabelas se preciso -->         <property name="hibernate.hbm2ddl.auto" value="update" />     </properties> </persistence-unit> 

i found in book read learn spring , hibernate. book name professional java web applications written nicholas s. williams. think helpful many people.

creating persistence configuration:

to use entities create, must define persistence unit. doing simple. create persistence.xml file not dissimilar deployment descriptor, far fewer options worry about. root element of persistence configuration file <persistence>. element may contain 1 or more <persistence-unit> elements. no other elements within <persistence>. <persistence-unit> has 2 attributes: name specifies name of persistence unit , transaction-type indicates whether persistence unit uses java transaction api (jta) transactions or standard local transactions. must specify name, how locate persistence unit in code. if not specified, transaction-type defaults jta in java ee application server , resource_local in java se environment or simple servlet container. however, prevent unexpected behavior it’s best set value explicitly instead of relying on default value. <persistence-unit> contains following inner elements. none of them required (so <persistence-unit> may empty); however, must specify whichever elements use in following order:

  • <description> contains useful description persistence unit. although makes reading persistence file easier, has no semantic value.
  • <provider> specifies qualified class name of javax.persistence.spi .persistenceprovider implementation used persistence unit. default, when persistence unit, api use first jpa provider on classpath. can include element mandate specific jpa provider.

  • you can use either <jta-data-source> or <non-jta-data-source> (but not both) use jndi datasource resource. may use <jta-data-source> if transaction-type jta; likewise may use <non-jta-data-source> if transaction-type resource_local. specifying datasource causes persistence unit use datasource entity operations.

  • <mapping-file> specifies classpath-relative path xml mapping file. if don’t specify <mapping-file>, provider looks orm.xml. may specify multiple <mapping-file> elements use multiple mapping files.

  • you can use 1 or more <jar-file> elements specify jar file or jar files jpa provider should scan mapping-annotated entities. @entity, @embeddable, @javax.persistence.mappedsuperclass, or @javax.persistence.converter classes found added persistence unit.

  • you can use 1 or more <class> elements indicate specific @entity, @embeddable, @mappedsuperclass, or @converter classes should added persistence unit. must annotate class or classes jpa annotations.

  • using <exclude-unlisted-classes /> or <exclude-unlisted-classes>true</exclude-unlisted-classes> indicates provider should ignore classes not specified <jar-file> or <class>. omitting <exclude-unlisted-classes> or using <exclude-unlisted-classes>false</exclude-unlisted-classes> causes jpa provider scan classpath location of persistence file jpa-annotated classes. if persistence.xml located in jar file, jar file (and jar file) scanned classes. if persistence.xml located in directory-based classpath location (such / web-inf/classes), directory (and directory) scanned classes. prior hibernate 4.3.0 , spring framework 3.2.5, specifying element value false incorrectly interpreted true.

  • <shared-cache-mode> indicates how entities cached in persistence unit (if jpa provider supports caching, optional). none disables caching, whereas enables caching entities. enable_selective means entities annotated @javax .persistence.cacheable or @cacheable(true) (or marked cacheable in orm.xml) cached. disable_selective results in caching of entities except annotated @cacheable(false) (or marked non-cacheable in orm.xml). default value, unspecified, means jpa provider decides effective default is. hibernate orm defaults enable_selective, relying on not portable.

  • <validation-mode> indicates if , how bean validation should applied entities. none means bean validation not enabled, whereas callback makes provider validate entities on insert, update, , delete. auto has effective value of callback if bean validation provider exists on classpath , effective value of none if no bean validation provider exists on classpath. if enable validation, jpa provider configures new validator validate entities. if have configured special spring framework validator custom localized error codes, jpa provider ignores it. such, it’s best set validation mode none , use bean validation before persistence layer invoked.

  • <properties> provides way specify other jpa properties, including standard jpa properties (such jdbc connection string, username, , password, or schema generation settings) provider-specific properties (such hibernate settings). specify 1 or more properties using nested elements, each name , value attribute.

nicholas s. williams, professional java web applications, (indianapolis, indiana: john wiley & sons, inc., 2014), pg 584-585


Comments