You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
DATACMNS-763 - Fixed constructor in example of custom repository base class.
Added hint to which constructor of the superclass to override. Added test cas e to make sure the expected types are advertised in the case of an error.
or via <<repositories.create-instances,XML configuration>>:
135
139
+
140
+
136
141
[source, xml]
137
142
----
138
143
<?xml version="1.0" encoding="UTF-8"?>
@@ -148,13 +153,15 @@ or via <<repositories.create-instances,XML configuration>>:
148
153
149
154
</beans>
150
155
----
156
+
151
157
+
152
158
The JPA namespace is used in this example. If you are using the repository abstraction for any other store, you need to change this to the appropriate namespace declaration of your store module which should be exchanging `jpa` in favor of, for example, `mongodb`.
153
-
159
+
+
154
160
Also, note that the JavaConfig variant doesn't configure a package explictly as the package of the annotated class is used by default. To customize the package to scan use one of the `basePackage…` attribute of the data-store specific repository `@Enable…`-annotation.
155
161
156
162
. Get the repository instance injected and use it.
157
163
+
164
+
158
165
[source, java]
159
166
----
160
167
public class SomeClient {
@@ -578,8 +585,9 @@ public class MyRepositoryImpl<T, ID extends Serializable>
578
585
579
586
private final EntityManager entityManager;
580
587
581
-
public MyRepositoryImpl(Class<T> domainClass, EntityManager entityManager) {
582
-
super(domainClass, entityManager);
588
+
public MyRepositoryImpl(JpaEntityInformation entityInformation,
589
+
EntityManager entityManager) {
590
+
super(entityInformation, entityManager);
583
591
584
592
// Keep the EntityManager around to used from the newly introduced methods.
585
593
this.entityManager = entityManager;
@@ -592,6 +600,8 @@ public class MyRepositoryImpl<T, ID extends Serializable>
592
600
----
593
601
====
594
602
603
+
WARNING: The class needs to have a constructor of the super class which the store-specific repository factory implementation is using. In case the repository base class has multiple constructors, override the one taking an `EntityInformation` plus a store specific infrastructure object (e.g. an `EntityManager` or a template class).
604
+
595
605
The default behavior of the Spring `<repositories />` namespace is to provide an implementation for all interfaces that fall under the `base-package`. This means that if left in its current state, an implementation instance of `MyRepository` will be created by Spring. This is of course not desired as it is just supposed to act as an intermediary between `Repository` and the actual repository interfaces you want to define for each entity. To exclude an interface that extends `Repository` from being instantiated as a repository instance, you can either annotate it with `@NoRepositoryBean` (as seen above) or move it outside of the configured `base-package`.
596
606
597
607
The final step is to make the Spring Data infrastructure aware of the customized repository base class. In JavaConfig this is achieved by using the `repositoryBaseClass` attribute of the `@Enable…Repositories` annotation:
0 commit comments