-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 
Author Message
 Post subject: java.lang.nullPointerException on hibernate search
PostPosted: Fri May 16, 2008 1:24 pm 
Regular
Regular

Joined: Tue Apr 01, 2008 5:39 pm
Posts: 61
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version:
3.2.6. GA

Mapping documents:
Annotation.
Code:

@Indexed
@Analyzer(impl=StandardAnalyzer.class)
public class AuditTrail implements Serializable {
    private static final long serialVersionUID = 54324L;

    @DocumentId
    private Integer id;

    @Field(index=Index.TOKENIZED, store=Store.YES)
    private String function;

    @Field(index=Index.TOKENIZED, store=Store.YES)
    private String attribute;

    @Field(index=Index.TOKENIZED, store=Store.YES)
    private String oldValue;

    @Field(index=Index.TOKENIZED, store=Store.YES)
    private String newValue;

    @IndexedEmbedded
    private User createBy;

    @Field(index=Index.TOKENIZED, store=Store.YES)
    private String note;

    @Field(index=Index.UN_TOKENIZED)
    @DateBridge(resolution=Resolution.MILLISECOND)
    private Timestamp createOn;

    public AuditTrail(final User createBy)
    {
        this.createBy = createBy;
    }

    @SuppressWarnings("unused")
    private AuditTrail()
    {
        // do nothing
    }
    public Integer getId() {
        return this.id;
    }

    public String getOldValue() {
        return this.oldValue;
    }

    public void setOldValue(final String oldValue) {
        this.oldValue = oldValue;
    }

    public String getNewValue() {
        return this.newValue;
    }

    public void setNewValue(final String newValue) {
        this.newValue = newValue;
    }

    public Timestamp getCreateOn() {
        return this.createOn;
    }

    public String getNote() {
        return this.note;
    }

    public void setNote(String note) {
        this.note = note;
    }

    public String getFunction() {
        return this.function;
    }
    public void setFunction(String function) {
        this.function = function;
    }

    public String getAttribute() {
        return this.attribute;
    }
    public void setAttribute(String attribute) {
        this.attribute = attribute;
    }

    public User getCreateBy() {
        return this.createBy;
    }

    /* (non-Javadoc)
     * @see java.lang.Object#equals(java.lang.Object)
     */
    @Override
    public boolean equals(Object obj) {
        if (!(obj instanceof AuditTrail))
            return false;
        final AuditTrail other = (AuditTrail) obj;
        return new EqualsBuilder()
        .append(this.id, other.getId())
        .isEquals();
    }

    /* (non-Javadoc)
     * @see java.lang.Object#hashCode()
     */
    @Override
    public int hashCode() {
        return new HashCodeBuilder()
        .append(this.id)
        .hashCode();
    }

    @Override
    public String toString()
    {
        return new ToStringBuilder(this)
        .append("id", this.id)
        .append("function", this.function)
        .append("attribute", this.attribute)
        .append("oldValue", this.oldValue)
        .append("newValue", this.newValue)
        .append("createBy", this.createBy)
        .append("createOn", this.createOn)
        .toString();
    }
}

Code between sessionFactory.openSession() and session.close():
Code:
@Override
    public List<AuditTrail> getBySearch(final String searchTerm, final String[] fields)   {
        getHibernateTemplate().setExposeNativeSession(true);
        return forceGenericList(getHibernateTemplate().executeWithNativeSession(
                new HibernateCallback()
                {
                    public Object doInHibernate(Session session) throws HibernateException
                    {
                        try
                        {
                            FullTextSession fullTextSession = Search.createFullTextSession(session);
                            QueryParser parser = new MultiFieldQueryParser(fields, new StandardAnalyzer());
                            Query query = parser.parse(searchTerm);
                            org.hibernate.Query fullTextQuery = fullTextSession.createFullTextQuery(query,AuditTrail.class);
                            return fullTextQuery.list();
                        }
                        catch (ParseException pe)
                        {
                            return null;
                        }
                        finally
                        {
                            getHibernateTemplate().setExposeNativeSession(false);
                        }
                    }
                }));
    }

Full stack trace of any exception that occurs:

Code:
java.lang.NullPointerException
   at java.io.StringReader.<init>(Unknown Source)
   at org.apache.lucene.queryParser.QueryParser.parse(QueryParser.java:144)
   at com.util.audit.AuditTrailDaoHibernateImpl$2.doInHibernate(AuditTrailDaoHibernateImpl.java:78)
   at org.springframework.orm.hibernate3.HibernateTemplate.doExecute(HibernateTemplate.java:419)
   at org.springframework.orm.hibernate3.HibernateTemplate.executeWithNativeSession(HibernateTemplate.java:374)
   at com.util.audit.AuditTrailDaoHibernateImpl.getBySearch(AuditTrailDaoHibernateImpl.java:69)
   at com.util.audit.AuditTrailServiceImpl.searchAuditedTrail(AuditTrailServiceImpl.java:35)


Name and version of the database you are using:
oracle 10g express edition.

The generated SQL (show_sql=true):

Debug level Hibernate log excerpt:



Problems with Session and transaction handling?

Read this: http://hibernate.org/42.html


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 16, 2008 1:57 pm 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
Hi,
what are the values of "fields" and "searchTerm"
Code:
QueryParser parser = new MultiFieldQueryParser(fields, new StandardAnalyzer());
Query query = parser.parse(searchTerm);
?

_________________
Sanne
http://in.relation.to/


Top
 Profile  
 
 Post subject:
PostPosted: Sat May 17, 2008 1:05 am 
Regular
Regular

Joined: Tue Apr 01, 2008 5:39 pm
Posts: 61
the fields are null. I think it is more of a spring web-flow issue error.


Top
 Profile  
 
 Post subject:
PostPosted: Sat May 17, 2008 2:43 am 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
yes it is: you can't give nulls to the MultiFieldQueryParser, so this is not a bug of the parser..
By the way, the QueryParser is part of the Lucene API.
regards,

_________________
Sanne
http://in.relation.to/


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.