Named query with a Pageable parameter - pagination

LOG.warn("Finder method {} is backed by a NamedQuery but contains a Pageable parameter! Sorting delivered this Pageable will not be applied!", method)
I'm getting the warning above. What is the reason of the warn?

Related

How can I start another activity with putextra class objects?

I want to start another activity with some set class object like NavigationViewOptions.
My code:
public NavigationViewOptions options;
options=NavigationViewOptions.builder()
.directionsRoute(currentRoute)
.shouldSimulateRoute(false)
.navigationListener(MainActivity.this)
.build();
Intent navigationActivity=new Intent(MainActivity.this,NavigationActivity.class);
navigationActivity.putExtra("navigationOptions", options); startActivity(navigationActivity);
And what I got build error "no suitable method for putextra"
Then I tried (Parselable)options or (Serializable)options like below
navigationActivity.putExtra("navigationOptions", (Parcelable) options);
navigationActivity.putExtra("navigationOptions", (Serializable) options);
I got build successful. But when I was running app on device, I got errors
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.mapbox_document, PID: 18374
java.lang.ClassCastException: com.mapbox.services.android.navigation.ui.v5.AutoValue_NavigationViewOptions cannot be cast to android.os.Parcelable
at com.example.mapbox_document.MainActivity$1.onClick(MainActivity.java:236)
at android.view.View.performClick(View.java:7346)
at android.widget.TextView.performClick(TextView.java:14275)
at android.view.View.performClickInternal(View.java:7312)
at android.view.View.access$3200(View.java:846)
at android.view.View$PerformClick.run(View.java:27794)
at android.os.Handler.handleCallback(Handler.java:873)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:7100)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:494)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:964)
I tried to add parcelable method to mainactivity class extends but I failed.
What is the method I have to follow?
For passing non primitive types via an intent between activities, you have 2 options:
Make the object parcelable or make it serializable.
In order for it to be parcelable (a parcel can be created from it), the NavigationViewOptions class would have to implement the Parcelable interface.
In order for it to be serializable (convertable from and to byte stream) the NavigationViewOptions class would have to implement the Serializable interface.
For reference have a look here: https://www.techjini.com/blog/passing-objects-via-intent-in-android/
Checking the implementation of NavigationViewOptions, I cannot find the implementation of neither the serializable nor the parcelable interface. Therefore passing the NavigationViewOptions object via an intent is not straightforward.
Recommendation:
I would recommend you to pass the primitive objects, that you use to build the NavigationViewOptions object with, instead of passing the object itself. The route object can be passed via an intent, as you can convert it to String. The other object is a Boolean. So this will work.

Hazelcast distributed query using indexes

I am trying to query Hazelcast map using predicates. My predicate code works fine without indexes but for better performance, I want to put index on the key my Hazelcast map.
Map Structure: IMap<Event, Long> - Event is a POJO class.
<map name="event.map">
<in-memory-format>NATIVE</in-memory-format>
<backup-count>2</backup-count>
<async-backup-count>0</async-backup-count>
<time-to-live-seconds>30</time-to-live-seconds>
<max-idle-seconds>0</max-idle-seconds>
<eviction-policy>LFU</eviction-policy>
<max-size policy="FREE_NATIVE_MEMORY_PERCENTAGE">25</max-size>
<cache-deserialized-values>INDEX-ONLY</cache-deserialized-values>
<indexes>
<index ordered="true">eventType</index>
</indexes>
</map>
With the above Map config, I get following exception:
Jul 19, 2019 10:04:21 PM com.hazelcast.map.impl.operation.HDEntryOperation
SEVERE: [127.0.0.1]:5701 [dev] [3.11.2] java.lang.IllegalArgumentException: There is no suitable accessor for 'eventType' on class 'java.lang.Long'
com.hazelcast.query.QueryException: java.lang.IllegalArgumentException: There is no suitable accessor for 'eventType' on class 'java.lang.Long'
at com.hazelcast.query.impl.getters.ReflectionHelper.createGetter(ReflectionHelper.java:175)
at com.hazelcast.query.impl.getters.Extractors.instantiateGetter(Extractors.java:124)
at com.hazelcast.query.impl.getters.Extractors.getGetter(Extractors.java:101)
at com.hazelcast.query.impl.getters.Extractors.extract(Extractors.java:63)
at com.hazelcast.query.impl.QueryableEntry.extractAttributeValueFromTargetObject(QueryableEntry.java:144)
at com.hazelcast.query.impl.QueryableEntry.extractAttributeValue(QueryableEntry.java:82)
at com.hazelcast.query.impl.QueryableEntry.getAttributeValue(QueryableEntry.java:48)
at com.hazelcast.query.impl.QueryableEntry.getConverter(QueryableEntry.java:67)
at com.hazelcast.query.impl.IndexImpl.saveEntryIndex(IndexImpl.java:79)
at com.hazelcast.query.impl.Indexes.saveEntryIndex(Indexes.java:164)
at com.hazelcast.map.impl.recordstore.AbstractRecordStore.saveIndex(AbstractRecordStore.java:165)
at com.hazelcast.map.impl.recordstore.DefaultRecordStore.putInternal(DefaultRecordStore.java:709)
at com.hazelcast.map.impl.recordstore.DefaultRecordStore.setWithUncountedAccess(DefaultRecordStore.java:987)
at com.hazelcast.map.impl.operation.EntryOperator.onAddedOrUpdated(EntryOperator.java:288)
at com.hazelcast.map.impl.operation.EntryOperator.doPostOperateOps(EntryOperator.java:219)
at com.hazelcast.map.impl.operation.HDEntryOperation.runVanilla(HDEntryOperation.java:257)
at com.hazelcast.map.impl.operation.HDEntryOperation.runInternal(HDEntryOperation.java:95)
at com.hazelcast.map.impl.operation.HDMapOperation.run(HDMapOperation.java:88)
at com.hazelcast.spi.Operation.call(Operation.java:170)
at com.hazelcast.spi.impl.operationservice.impl.OperationRunnerImpl.call(OperationRunnerImpl.java:208)
at com.hazelcast.spi.impl.operationservice.impl.OperationRunnerImpl.run(OperationRunnerImpl.java:197)
at com.hazelcast.spi.impl.operationexecutor.impl.OperationExecutorImpl.run(OperationExecutorImpl.java:407)
at com.hazelcast.spi.impl.operationexecutor.impl.OperationExecutorImpl.runOrExecute(OperationExecutorImpl.java:434)
at com.hazelcast.spi.impl.operationservice.impl.Invocation.doInvokeLocal(Invocation.java:586)
at com.hazelcast.spi.impl.operationservice.impl.Invocation.doInvoke(Invocation.java:571)
at com.hazelcast.spi.impl.operationservice.impl.Invocation.invoke0(Invocation.java:530)
at com.hazelcast.spi.impl.operationservice.impl.Invocation.invoke(Invocation.java:220)
at com.hazelcast.spi.impl.operationservice.impl.InvocationBuilderImpl.invoke(InvocationBuilderImpl.java:60)
at com.hazelcast.client.impl.protocol.task.AbstractPartitionMessageTask.processMessage(AbstractPartitionMessageTask.java:67)
at com.hazelcast.client.impl.protocol.task.AbstractMessageTask.initializeAndProcessMessage(AbstractMessageTask.java:123)
at com.hazelcast.client.impl.protocol.task.AbstractMessageTask.doRun(AbstractMessageTask.java:111)
at com.hazelcast.client.impl.protocol.task.AbstractMessageTask.run(AbstractMessageTask.java:101)
at com.hazelcast.spi.impl.operationservice.impl.OperationRunnerImpl.run(OperationRunnerImpl.java:161)
at com.hazelcast.spi.impl.operationexecutor.impl.OperationThread.process(OperationThread.java:159)
at com.hazelcast.spi.impl.operationexecutor.impl.OperationThread.process(OperationThread.java:127)
at com.hazelcast.spi.impl.operationexecutor.impl.OperationThread.run(OperationThread.java:110)
Caused by: java.lang.IllegalArgumentException: There is no suitable accessor for 'eventType' on class 'java.lang.Long'
at com.hazelcast.query.impl.getters.ReflectionHelper.createGetter(ReflectionHelper.java:168)
... 35 more
From the exception I understand that Hazelcast is trying to apply the index on the Value field of the IMap.
Is there a way index can be put on the Key field of the IMap?
Try
<indexes>
<index ordered="true">__key.eventType</index>
</indexes>
As a key-value store, it's usual to search on the values, so that's what the index expects. When you put eventType in the index it looks for that field in
the value. You need to change it to __key.eventType to make it look in the key.
If you need frequent search access to part of a composite primary key, as the index implements, then the choice of primary key structure may need reviewed.
Also, if you can, upgrade from 3.11.2 to 3.12.1. There are some querying improvements behind the scenes.

Hazelcast Supplier and Aggregation gives Concurrent Execution Exception

I am trying to get a set of the distinct values of an object's field stored in a Hazelcast map.
This line of java code:
instructions.aggregate(Supplier.all(value -> value.getWorkArea()), Aggregations.distinctValues());
has the following stacktrace :
java.util.concurrent.ExecutionException: com.hazelcast.nio.serialization.HazelcastSerializationException: java.lang.ClassNotFoundException: com.example.instruction.repository.HazelcastInstructionRepository$GeneratedEvaluationClass
com.hazelcast.nio.serialization.HazelcastSerializationException: java.lang.ClassNotFoundException: com.example.instruction.repository.HazelcastInstructionRepository$GeneratedEvaluationClass
java.lang.ClassNotFoundException: com.example.instruction.repository.HazelcastInstructionRepository$GeneratedEvaluationClass
If I were to try this line :
instructions.aggregate(Supplier.all()), Aggregations.distinctValues());
or:
instructions.aggregate(Supplier.fromPredicate(Predicates.and(Predicates.equal("type", "someType"), equal("groupId", null),
Predicates.equal("workArea", "someWorkArea"))), Aggregations.distinctValues());
It just works ... It seems to be something wrong when I am making a reference to the object's field. (I also tried it with other fields of the object and the same error gets returned)
This is running on my local environment and I am sure that the objects are being placed correctly in the Hazelcast map since the other aggregations/predicates are working.
Do you have any ideas about what am I doing wrong?
Many Thanks!
EDITED: So the problem is the closure. It's not available on all nodes. Only on the calling node.
Also. This feature is deprecated. Plz use the fast-aggregations instead.
http://docs.hazelcast.org/docs/latest/manual/html-single/#fast-aggregations

javax.el.ELException: Error reading 'foo' on type com.example.Bean

I am reading the following tutorial:
The expression used in the h:dataTable/#value normally specifies a property
name for which a getter was defined, which means that in the controller
BookController class a property books is defined (optional) as well as a
method named getBooks (this is mandatory). In this particular case it is
just sufficient to define the getBooks method since there is no need of the
books property in the controller class
I have been trying to work such an idea in my eclipse and tomcat 7. but it keeps tilling me:
javax.el.ELException: /views/books/listAll.xhtml #9,60 value="#{bookController.books}": Error reading 'books' on type pl.ctrl.BookController
My question is, is it possible to have:
<h:dataTable value="#{bookController.books}" var="b">
While there is no books property but just getBooks() getter method in #{bookController} managed bean?
Your problem is different than what the book tells. If JSF/EL couldn't find the getter method in its entirety, you would have gotten the below exception:
javax.el.PropertyNotFoundException: Property 'books' not found on type pl.ctrl.BookController
Or if it couldn't find the bean itself in its entirety:
javax.el.PropertyNotFoundException: Target Unreachable, identifier 'bookController' resolved to null
But instead you got:
javax.el.ELException: Error reading 'books' on type pl.ctrl.BookController
This means that the bean and the getter method was found, but invoking the getter method threw an exception. Basically, the following is happening under JSF/EL's covers:
try {
Object result = bookController.getBooks();
} catch (Exception e) {
throw new ELException("Error reading 'books' on type pl.ctrl.BookController", e);
}
Note the e being passed as cause of the ELException. The original exception must thus be visible as "Caused by" further down in the stack trace which you didn't post anywhere in the question. The bottommost one is the root cause of all and is the answer to your concrete problem. In case you're unable to interpret it, simply copypaste the exception type and message into a decent search engine to find answers and clues.
Unrelated to the concrete problem, an exception thrown from a getter method in turn indicates fishy code. A getter method isn't supposed to do any exception sensitive business logic. Namely, it can be invoked multiple times per bean's life and repeating the very same business logic over and over during all bean's life is plain inefficient. Stop doing that and move the business logic to an one time initialization or action/event listener method. The getter method must merely return the already-prepared property. See also Why JSF calls getters multiple times and How and when should I load the model from database for h:dataTable.

spring-ldap and #attributes annotation with spring-ldap 2.x ODM interface

There seems be some things missing in the Spring-LDAP ODM annotations. This is a question by way of a feature request, if there is a better way to contribute such requests, please say so.
I'd like to mark an #Attribute as read-only, so it will populate the bean from LDAP for reference, but not persist it back to ldap. I'd suggest adding an attribute read-only to #Attribute, defaulting to false, for the usual case. The default attributes of * misses all the operational attributes, some of which are very useful, and transfers more data than is required, slowing down the ldap query with attributes which will never be used.
An example of this; it would be very useful, for literally read only, such as entryUUID, etag, etc., which you cannot use if you wish to persist only some fields back to ldap, as the bean fails to persist to ldap with an exception when you save the bean. But also would be usefule for general fields which you want to structurally prevent the user from ever updating.
You can get around this by not annotating read-only fields, and then manually populating the read only fields with a separate call. Very messy and kills the query speed.
Also on a related topic, query() coudl have a default list of attributes, which you have already annotated in your classes, something like :
public static String[] getBeanAttributes(Class<?> beanClass) {
ArrayList<String> attrsObj = new ArrayList<>();
for (Field field : beanClass.getDeclaredFields()) {
if (field.isAnnotationPresent(Attribute.class)) {
Attribute attr = field.getAnnotation(Attribute.class);
attrsObj.add(attr.name());
}
}
String[] attrs = attrsObj.toArray(new String[attrsObj.size()]);
return attrs;
}
Above just returns a simple String[] of your declared attributes, to pass to query.attributes() - now i realize that as a static member, query() is built before the bean class is known, but at least there could be a helper function like the above, or a method signature for query attributes() that took a bean Class signature as an argument.
I created LDAP-312 on Jira. Thanks.

Resources