Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Another null pointer exception #42

Open
ghost opened this issue Jan 12, 2012 · 23 comments · Fixed by #45
Open

Another null pointer exception #42

ghost opened this issue Jan 12, 2012 · 23 comments · Fixed by #45

Comments

@ghost
Copy link

ghost commented Jan 12, 2012

Hi,

Using version 0.3 and the following code to search

QueryBuilder qb3 = QueryBuilders.termQuery("title", queryTitle.toLowerCase());

SearchResults<Listing> list = ElasticSearch.search(qb3, Listing.class);

this nullpointerexception is being thrown:

play.exceptions.JavaExecutionException
at play.mvc.ActionInvoker.invoke(ActionInvoker.java:229)
at Invocation.HTTP Request(Play!)
Caused by: java.lang.NullPointerException
at play.modules.elasticsearch.util.ReflectionUtil.setFieldValue(ReflectionUtil.java:351)
at play.modules.elasticsearch.util.ReflectionUtil.setFieldValue(ReflectionUtil.java:339)
at play.modules.elasticsearch.transformer.Transformer.toSearchResults(Transformer.java:68)
at play.modules.elasticsearch.Query.fetch(Query.java:173)
at play.modules.elasticsearch.ElasticSearch.search(ElasticSearch.java:145)
at play.modules.elasticsearch.ElasticSearch.search(ElasticSearch.java:96)
at models.Listing.search(Listing.java:285)
at controllers.BidAndBuy.search(BidAndBuy.java:15)
at play.mvc.ActionInvoker.invokeWithContinuation(ActionInvoker.java:546)
at play.mvc.ActionInvoker.invoke(ActionInvoker.java:500)
at play.mvc.ActionInvoker.invokeControllerMethod(ActionInvoker.java:476)
at play.mvc.ActionInvoker.invokeControllerMethod(ActionInvoker.java:471)
at play.mvc.ActionInvoker.invoke(ActionInvoker.java:159)
... 1 more

@bgooren
Copy link
Contributor

bgooren commented Jan 15, 2012

Can you please add the Listing model to your issue report?
The NPE is caused by a field in your index having a different name as a field in your model.

I've done quite some work on the JPATransformer, which fetches the models from database, but the Transformer has not (yet) been updated accordingly (see #32).

In case you are using @ElasticSearchField annotations, this is what is probably causing the NPE. If you show us your Listing model we can confirm and help to fix it.

@ghost
Copy link
Author

ghost commented Jan 15, 2012

The Listing model (only the field/property definitions) is shown below.
I am defining my own field names in the JPA annotations, maybe there is
an issue there. Also the es-admin page provided by the module is able
to search on the model. I'm very new to all this but I suspect is uses the
JSON interface of ElasticSearch and not the Java interface so there could
be a difference.

@Entity
public class Listing extends Model
{
    @Required
    @Column(nullable=false)
    public String title;

    @Lob
    public String description;

    @ElasticSearchEmbedded(fields={"name", "description"})
    @Required
    @ManyToOne(optional=false, fetch=FetchType.LAZY)
    @JoinColumn(name="productCategoryId", nullable=false)
    public Category productCategory;

    @ElasticSearchEmbedded(fields={"type"})
    @Required
    @ManyToOne(optional=false, fetch=FetchType.LAZY)
    @JoinColumn(name="listingOwnerTypeId", nullable=false)
    public ListingOwnerType listingOwnerType;

    @ElasticSearchEmbedded(fields={"firstName", "lastName"})
    @ManyToOne(fetch=FetchType.LAZY)
    @JoinColumn(name="vendorOwnerId")
    public Vendor vendorOwner;

    @ElasticSearchEmbedded(fields={"firstName", "lastName"})
    @ManyToOne(fetch=FetchType.LAZY)
    @JoinColumn(name="agentOwnerId")
    public Agent agentOwner;

    @Column(nullable = false)
    public int maximumShareCount;

    @Column(nullable = false, precision = 15, scale=2)
    public BigDecimal reservePrice;

    @Column(nullable=false)
    public boolean reserveMet;

    @Required
    @MaxSize(255)
    @Column(nullable=false)
    public String street1;

    @MaxSize(255)
    @Column(nullable=true)
    public String street2;

    @Required
    @Column(nullable=false)
    public int cityId;

    @Required
    @Column(nullable=false)
    public int regionId;

    @Required
    @MaxSize(25)
    @Column(length=25, nullable=false)
    public String postCode;

    @Required
    @Column(nullable=false)
    public int countryId;

    @ElasticSearchIgnore
    @Required
    @Column(nullable=false)
    @Temporal(TemporalType.TIMESTAMP)
    public Date postDate;

    @Required
    @Column(nullable=false)
    @Temporal(TemporalType.TIMESTAMP)
    public Date auctionStartDate;

    @Required
    @Column(nullable=false)
    @Temporal(TemporalType.TIMESTAMP)
    public Date auctionEndDate;

    @Column(nullable=true)
    @Temporal(TemporalType.TIMESTAMP)
    public Date gggStartDate;

    @Column(nullable=true)
    @Temporal(TemporalType.TIMESTAMP)
    public Date gggEndDate;

    @Column(nullable=true)
    public int gggInitialDuration;

    @Column(nullable=true)
    public int gggExtensionDuration;

    @ElasticSearchEmbedded(fields={"type"})
    @Required
    @ManyToOne(optional=false, fetch=FetchType.LAZY)
    @JoinColumn(name="typeId", nullable=false)
    public AuctionType auctionType;

    @ElasticSearchEmbedded(fields={"state"})
    @Required
    @ManyToOne(optional=false, fetch=FetchType.LAZY)
    @JoinColumn(name="stateId", nullable=false)
    public ListingState state;

@ghost
Copy link
Author

ghost commented Jan 15, 2012

I just read issue #32 and it seems to be the problem I am facing.

@bgooren
Copy link
Contributor

bgooren commented Jan 15, 2012

Thanks for posting your model. Yes, it appears that the use of @es annotations causes your NPE.

I only use the JPATransformer myself, so this is a good case to update the Transformer. I'll get back to you when I make some progress on it.

@ghost
Copy link
Author

ghost commented Jan 26, 2012

My apologies if I sound demanding but do you have a rough estimate of completing the updating of the Transformer?

@bgooren
Copy link
Contributor

bgooren commented Jan 26, 2012

I'll try to make some progress this weekend :)

@ghost
Copy link
Author

ghost commented Jan 27, 2012

Thanks mate :)

@bgooren bgooren mentioned this issue Jan 28, 2012
@bgooren
Copy link
Contributor

bgooren commented Jan 28, 2012

Hi, as you can see I've commited some new code. It requires more testing; I mainly use the JPA-hydrated-results path, so please provide feedback once you have tested the new code.

Are you able to roll your own (test) release so you test it out, or do you need a new "official" release for that?

@ghost
Copy link
Author

ghost commented Jan 28, 2012

You're a legend. I'll have a go later today.

@bgooren
Copy link
Contributor

bgooren commented Jan 30, 2012

Have you been able to have a go with the new code?

@ghost
Copy link
Author

ghost commented Feb 1, 2012

My apologies I have been dealing with client woes. I did pull the latest version from github but I couldn't get it to work. Something about ElasticSearch dont being abled to be resolved in the ElasticSearchController. I think it had to do with the java library path. I'll try it again, if I can't get it to work maybe a new official release is needed for us noobs.

Thanks again.

@bgooren
Copy link
Contributor

bgooren commented Feb 6, 2012

Hi, have you had another chance to take a look?

@ghost
Copy link
Author

ghost commented Feb 6, 2012

Hi,

I keep on getting the following error:

Compilation error (In {module:elasticsearch-0.4}/app/models/elasticsearch/ElasticSearchSampleModel.java around line 30)
The file {module:elasticsearch-0.4}/app/models/elasticsearch/ElasticSearchSampleModel.java could not be compiled. Error raised is : play.modules.elasticsearch.annotations.ElasticSearchable cannot be resolved to a type

play.exceptions.CompilationException: play.modules.elasticsearch.annotations.ElasticSearchable cannot be resolved to a type
    at play.classloading.ApplicationCompiler$2.acceptResult(ApplicationCompiler.java:246)
    at org.eclipse.jdt.internal.compiler.Compiler.handleInternalException(Compiler.java:672)
    at org.eclipse.jdt.internal.compiler.Compiler.compile(Compiler.java:516)
    at play.classloading.ApplicationCompiler.compile(ApplicationCompiler.java:278)
    at play.classloading.ApplicationClasses$ApplicationClass.compile(ApplicationClasses.java:249)
    at play.classloading.ApplicationClassloader.loadApplicationClass(ApplicationClassloader.java:156)
    at play.classloading.ApplicationClassloader.loadClass(ApplicationClassloader.java:84)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
    at play.classloading.ApplicationClasses.getAssignableClasses(ApplicationClasses.java:61)
    at play.classloading.ApplicationClassloader.getAssignableClasses(ApplicationClassloader.java:443)
    at {module:crud}/app/views/tags/crud/types.tag.(line:3)
    at play.templates.GroovyTemplate.internalRender(GroovyTemplate.java:229)
    at play.templates.GroovyTemplate$ExecutableTemplate.invokeTag(GroovyTemplate.java:374)
    at {module:crud}/conf/routes.(line:4)
    at play.templates.GroovyTemplate.internalRender(GroovyTemplate.java:229)
    at play.templates.Template.render(Template.java:26)
    at play.templates.GroovyTemplate.render(GroovyTemplate.java:184)
    at play.mvc.Router.parse(Router.java:162)
    at play.mvc.Router.parse(Router.java:190)
    at play.mvc.Router.parse(Router.java:164)
    at play.mvc.Router.load(Router.java:50)
    at play.mvc.Router.detectChanges(Router.java:219)
    at Invocation.HTTP Request(Play!)
02:58:03,311 ERROR ~ 

@69ah8mo4j
Internal Server Error (500) for request GET /favicon.ico

Compilation error (In {module:elasticsearch-0.4}/app/models/elasticsearch/ElasticSearchSampleModel.java around line 30)
The file {module:elasticsearch-0.4}/app/models/elasticsearch/ElasticSearchSampleModel.java could not be compiled. Error raised is : play.modules.elasticsearch.annotations.ElasticSearchable cannot be resolved to a type

play.exceptions.CompilationException: play.modules.elasticsearch.annotations.ElasticSearchable cannot be resolved to a type
    at play.classloading.ApplicationCompiler$2.acceptResult(ApplicationCompiler.java:246)
    at org.eclipse.jdt.internal.compiler.Compiler.handleInternalException(Compiler.java:672)
    at org.eclipse.jdt.internal.compiler.Compiler.compile(Compiler.java:516)
    at play.classloading.ApplicationCompiler.compile(ApplicationCompiler.java:278)
    at play.classloading.ApplicationClasses$ApplicationClass.compile(ApplicationClasses.java:249)
    at play.classloading.ApplicationClassloader.loadApplicationClass(ApplicationClassloader.java:156)
    at play.classloading.ApplicationClassloader.loadClass(ApplicationClassloader.java:84)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
    at play.classloading.ApplicationClasses.getAssignableClasses(ApplicationClasses.java:61)
    at play.classloading.ApplicationClassloader.getAssignableClasses(ApplicationClassloader.java:443)
    at {module:crud}/app/views/tags/crud/types.tag.(line:3)
    at play.templates.GroovyTemplate.internalRender(GroovyTemplate.java:229)
    at play.templates.GroovyTemplate$ExecutableTemplate.invokeTag(GroovyTemplate.java:374)
    at {module:crud}/conf/routes.(line:4)
    at play.templates.GroovyTemplate.internalRender(GroovyTemplate.java:229)
    at play.templates.Template.render(Template.java:26)
    at play.templates.GroovyTemplate.render(GroovyTemplate.java:184)
    at play.mvc.Router.parse(Router.java:162)
    at play.mvc.Router.parse(Router.java:190)
    at play.mvc.Router.parse(Router.java:164)
    at play.mvc.Router.load(Router.java:50)
    at play.mvc.Router.detectChanges(Router.java:219)
    at Invocation.HTTP Request(Play!)

It's not finding the elasticsearch play module. Any ideas?

Thanks
Burak

@bgooren
Copy link
Contributor

bgooren commented Feb 7, 2012

If you add the git repo as a project in your IDE (I use eclipse), you need to add "src" as a source folder, otherwise it won't find the play module itself.

@ghost
Copy link
Author

ghost commented Feb 15, 2012

My apologies for the late response. I have the src folder linked into the project now, however the MapperTransformer.java file seems to be missing from the repo.

@bgooren
Copy link
Contributor

bgooren commented Feb 15, 2012

You are right, See #47

@ghost
Copy link
Author

ghost commented Feb 21, 2012

Finally got some time to look at the search today but unfortunately I'm still having problems with the pathing of modules. I've added the git repo to eclipse, added the src folder. I tried modifying the .classpath file myself. Linked folders in my main project as well but to no avail. The only difference I see when compared to the 0.3 version is that in the .classpath file there is a link to a jar file play-elasticsearch.jar as well as the linked source folder "src".

Is it possible to create a new play framework module (0.4) so that I can just pull it into the project using play install module???

@bgooren
Copy link
Contributor

bgooren commented Feb 27, 2012

I will ask felipe to roll a new release; The new functionality needs to be explicity enabled so it won't break existing code.

@bgooren
Copy link
Contributor

bgooren commented Feb 29, 2012

Hi, 0.4 was just released. Please give it a try and report back.

@ghost
Copy link
Author

ghost commented Mar 1, 2012

Thank you for version 0.4 (This is my first java project, I didn't know what I was missing to get the module working from the repo).

I am receiving another null pointer exception. I am using the model I listed earlier in the thread and the following search command:

SearchResults<Listing> listings = ElasticSearch.search(QueryBuilders.fieldQuery("title", title), Listing.class);

which results in the following exception:

@69h6j27b3
Internal Server Error (500) for request POST /search/findlisting

Execution exception (In /app/controllers/Search.java around line 26)
NullPointerException occured : null

play.exceptions.JavaExecutionException
    at play.mvc.ActionInvoker.invoke(ActionInvoker.java:229)
    at Invocation.HTTP Request(Play!)
Caused by: java.lang.NullPointerException
    at play.modules.elasticsearch.util.ReflectionUtil.setFieldValue(ReflectionUtil.java:412)
    at play.modules.elasticsearch.util.ReflectionUtil.setFieldValue(ReflectionUtil.java:397)
    at play.modules.elasticsearch.transformer.SimpleTransformer.toSearchResults(SimpleTransformer.java:75)
    at play.modules.elasticsearch.Query.fetch(Query.java:190)
    at play.modules.elasticsearch.ElasticSearch.search(ElasticSearch.java:145)
    at play.modules.elasticsearch.ElasticSearch.search(ElasticSearch.java:96)
    at controllers.Search.findListing(Search.java:26)
    at play.mvc.ActionInvoker.invokeWithContinuation(ActionInvoker.java:546)
    at play.mvc.ActionInvoker.invoke(ActionInvoker.java:500)
    at play.mvc.ActionInvoker.invokeControllerMethod(ActionInvoker.java:476)
    at play.mvc.ActionInvoker.invokeControllerMethod(ActionInvoker.java:471)
    at play.mvc.ActionInvoker.invoke(ActionInvoker.java:159)
    ... 1 more

@ghost
Copy link
Author

ghost commented Mar 1, 2012

Looks like the MapperTransformer class isn't being utilised.

@bgooren
Copy link
Contributor

bgooren commented Mar 1, 2012

Hi, to prevent other users from getting problems (as the new code is relatively untested), you need to explicitly enable it.

Please use

Query<Listing> query = ElasticSearch.query( QueryBuilders.fieldQuery("title", title), Listing.class );
query.useMapper( true );
SearchResults<Listing> listings = query.fetch();

to enable the MapperTransformer for a query.

@ghost
Copy link
Author

ghost commented Mar 6, 2012

Thanks mate, everything seems to be working. I'll close the thread next week after some more testing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant