Spring Data JPA XML configuration¶
Spring Data JPA XML configuration involves defining the core infrastructure beans—such as the EntityManagerFactory, transaction manager, and repository scanning—within an XML application context file.^[600-developer__java__application-server__weblogic__weblogic-spring-jpa.md]
Core Configuration¶
The configuration typically relies on the LocalContainerEntityManagerFactoryBean to set up the JPA provider.^[600-developer__java__application-server__weblogic__weblogic-spring-jpa.md] This bean requires a defined DataSource and often specifies a LoadTimeWeaver (e.g., InstrumentationLoadTimeWeaver) for instrumentation purposes.^[600-developer__java__application-server__weblogic__weblogic-spring-jpa.md]
The JPA Vendor Adapter is configured to define database-specific behaviors, such as the target database (e.g., ORACLE), DDL generation settings, and SQL logging options.^[600-developer__java__application-server__weblogic__weblogic-spring-jpa.md] Common properties passed to the JPA provider include the Hibernate dialect, SQL formatting, and the hbm2ddl.auto strategy.^[600-developer__java__application-server__weblogic__weblogic-spring-jpa.md]
To enable transaction management, a JpaTransactionManager is defined, referencing the EntityManagerFactory.^[600-developer__java__application-server__weblogic__weblogic-spring-jpa.md] Annotation-driven transactions are subsequently enabled via the <tx:annotation-driven> tag.^[600-developer__java__application-server__weblogic__weblogic-spring-jpa.md]
Repository Configuration¶
Spring Data JPA repositories are activated using the jpa:repositories namespace element.^[600-developer__java__application-server__weblogic__weblogic-spring-jpa.md]
The base-package attribute specifies the Java packages to scan for repository interfaces (e.g., core.*.persistence).^[600-developer__java__application-server__weblogic__weblogic-spring-jpa.md] Additionally, the configuration must link the repositories to the correct entity-manager-factory-ref if multiple factories exist.^[600-developer__java__application-server__weblogic__weblogic-spring-jpa.md]
Entity Scanning and Component Scanning¶
Entity discovery is configured using the packagesToScan property of the LocalContainerEntityManagerFactoryBean, allowing the container to locate @Entity classes in specific packages (e.g., core.*).^[600-developer__java__application-server__weblogic__weblogic-spring-jpa.md]
Separately, the context:component-scan element is used to detect Spring components, such as stereotype-annotated model classes, within the defined base packages.^[600-developer__java__application-server__weblogic__weblogic-spring-jpa.md]
Manual Bean Definition¶
While the jpa:repositories element handles standard interfaces, specific repository implementation classes (e.g., custom implementations) can be explicitly registered as standard beans within the XML configuration.^[600-developer__java__application-server__weblogic__weblogic-spring-jpa.md]
Sources¶
^[600-developer__java__application-server__weblogic__weblogic-spring-jpa.md]