|
30 | 30 | import javax.persistence.Entity; |
31 | 31 | import javax.persistence.MappedSuperclass; |
32 | 32 | import javax.persistence.PersistenceException; |
| 33 | +import javax.persistence.SharedCacheMode; |
| 34 | +import javax.persistence.ValidationMode; |
33 | 35 | import javax.persistence.spi.PersistenceUnitInfo; |
34 | 36 | import javax.sql.DataSource; |
35 | 37 |
|
|
68 | 70 | * DataSource names are by default interpreted as JNDI names, and no load time weaving |
69 | 71 | * is available (which requires weaving to be turned off in the persistence provider). |
70 | 72 | * |
| 73 | + * <p><b>NOTE: Spring's JPA support requires JPA 2.0 or higher, as of Spring 4.0.</b> |
| 74 | + * Spring's persistence unit bootstrapping automatically detects JPA 2.1 at runtime. |
| 75 | + * |
71 | 76 | * @author Juergen Hoeller |
72 | 77 | * @since 2.0 |
73 | 78 | * @see #setPersistenceXmlLocations |
@@ -124,6 +129,10 @@ public class DefaultPersistenceUnitManager |
124 | 129 |
|
125 | 130 | private String[] mappingResources; |
126 | 131 |
|
| 132 | + private SharedCacheMode sharedCacheMode; |
| 133 | + |
| 134 | + private ValidationMode validationMode; |
| 135 | + |
127 | 136 | private DataSourceLookup dataSourceLookup = new JndiDataSourceLookup(); |
128 | 137 |
|
129 | 138 | private DataSource defaultDataSource; |
@@ -210,6 +219,24 @@ public void setMappingResources(String... mappingResources) { |
210 | 219 | this.mappingResources = mappingResources; |
211 | 220 | } |
212 | 221 |
|
| 222 | + /** |
| 223 | + * Specify the JPA 2.0 shared cache mode for all of this manager's persistence |
| 224 | + * units, overriding any value in {@code persistence.xml} if set. |
| 225 | + * @see javax.persistence.spi.PersistenceUnitInfo#getSharedCacheMode() |
| 226 | + */ |
| 227 | + public void setSharedCacheMode(SharedCacheMode sharedCacheMode) { |
| 228 | + this.sharedCacheMode = sharedCacheMode; |
| 229 | + } |
| 230 | + |
| 231 | + /** |
| 232 | + * Specify the JPA 2.0 validation mode for all of this manager's persistence |
| 233 | + * units, overriding any value in {@code persistence.xml} if set. |
| 234 | + * @see javax.persistence.spi.PersistenceUnitInfo#getValidationMode() |
| 235 | + */ |
| 236 | + public void setValidationMode(ValidationMode validationMode) { |
| 237 | + this.validationMode = validationMode; |
| 238 | + } |
| 239 | + |
213 | 240 | /** |
214 | 241 | * Specify the JDBC DataSources that the JPA persistence provider is supposed |
215 | 242 | * to use for accessing the database, resolving data source names in |
@@ -324,9 +351,6 @@ public PersistenceUnitPostProcessor[] getPersistenceUnitPostProcessors() { |
324 | 351 | * VM agent specified on JVM startup, and ReflectiveLoadTimeWeaver, which interacts |
325 | 352 | * with an underlying ClassLoader based on specific extended methods being available |
326 | 353 | * on it (for example, interacting with Spring's TomcatInstrumentableClassLoader). |
327 | | - * <p><b>NOTE:</b> As of Spring 2.5, the context's default LoadTimeWeaver (defined |
328 | | - * as bean with name "loadTimeWeaver") will be picked up automatically, if available, |
329 | | - * removing the need for LoadTimeWeaver configuration on each affected target bean.</b> |
330 | 354 | * Consider using the {@code context:load-time-weaver} XML tag for creating |
331 | 355 | * such a shared LoadTimeWeaver (autodetecting the environment by default). |
332 | 356 | * @see org.springframework.instrument.classloading.InstrumentationLoadTimeWeaver |
@@ -383,6 +407,12 @@ public void preparePersistenceUnitInfos() { |
383 | 407 | if (pui.getNonJtaDataSource() == null) { |
384 | 408 | pui.setNonJtaDataSource(this.defaultDataSource); |
385 | 409 | } |
| 410 | + if (this.sharedCacheMode != null) { |
| 411 | + pui.setSharedCacheMode(this.sharedCacheMode); |
| 412 | + } |
| 413 | + if (this.validationMode != null) { |
| 414 | + pui.setValidationMode(this.validationMode); |
| 415 | + } |
386 | 416 | if (this.loadTimeWeaver != null) { |
387 | 417 | pui.init(this.loadTimeWeaver); |
388 | 418 | } |
|
0 commit comments