on 10-18-2016 4:42 PM
I am searching products with flexible query which is working fine on hac. While writing flexible query in my java class I want to disable all restriction and for that I am using following code
public class abc
{
@Resource
private UserService userService;
private SearchRestrictionService searchRestrictionService;
public List<ProductModel> findProducts()
{
final String query = "select {p:name},{p.creationtime},from {Product! as p} ";
userService.setCurrentUser(userService.getAdminUser());
try
{
this.searchRestrictionService.disableSearchRestrictions();
}
catch (final NullPointerException e)
{
System.out.println("Problem in restriction");
e.printStackTrace();
}
} }
Above is a part of my code. On executing above code I am getting message in output as "Problem in restriction" as I have set this message for null pointer exception. Please suggest ho can i remove this exception from restriction property.
@Resource was missing before searchRestrictionService variable declaration. It should be like this :-
@Resource
private SearchRestrictionService searchRestrictionService;
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
searchRestrictionService is not injected into you abc class, due to that reason your getting NullPointerException.
As told please inject searchRestrictionService into you abc class. This will solve the NPE.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
3 | |
1 | |
1 | |
1 | |
1 | |
1 | |
1 | |
1 | |
1 | |
1 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.