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