Hibernate-search configuration trouble
by Richard Boehme
Hi there. I'm having problems using hibernate-search. I'm running on
Hibernate 3.2.4, hibernate-annotations-3.3.0.GA, and
hibernate-search-3.0.0.CR1. I'm also using Spring 2.0.6 and JBoss
4.2.1.GA. Now that I've got the version details out of the way, on to
the problem:
When I try to index a class that should be indexable, Hibernate dups a
stack trace starting with:
Hibernate Search Event listeners not configured, please check the
reference documentation and the application's hibernate.cfg.xml
I have followed the directions in the Hibernate search documentation
on creating a hibernate index; I've annotated the class that I want to
search and configured my sessionFactory's HibernateProperties to add
the directory_provider and indexBase in my
applicationContext-hibernate.xml.
@Entity
@Indexed
public class ZZZ extends YYY
{
@DocumentId
private Long id;
@Field(index=Index.TOKENIZED, store=Store.NO)
private String zzzId;
.
.
.
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource"><ref bean="dataSource"/></property>
<property name="mappingResources">
<list>
<value>com/adaptiverfid/model/ZZZ.hbm.xml</value>
<!-- snip more details -->
</list>
</property>
<property name="hibernateProperties">
<props>
<!-- snip working database details -->
<prop
key="hibernate.search.default.directory_provider">org.hibernate.search.store.FSDirectoryProvider</prop>
<prop
key="hibernate.search.default.indexBase">/path/to/already/created/dir</prop>
</props>
</property>
</bean>
I also have the hibernate-search, hibernate-annotations,
hibernate-commons-annotations, and lucene jars in my classpath. I have
tried adding post-commit-update, post-commit-delete- and
post-commit-update eventListeners to the sessionFactory bean, but that
doesn't help.
Googling gives me a version control entry that indicates that message
had been changed to be clearer than the one that said that the Lucene
event listeners need to be configured.
My indexing function is per the documentation's example; I simply pass
my list of objects to index in and it indexes them (I've also tried
commenting out the transaction, with the same results).
public void reindexForSearch(List list)
{
Session session =
SessionFactoryUtils.getSession(this.getSessionFactory(), true);
FullTextSession fullTextSession = Search.createFullTextSession(session);
Transaction tx = fullTextSession.beginTransaction();
for(Object obj : list)
{
fullTextSession.index(obj);
}
tx.commit();
SessionFactoryUtils.releaseSession(session, this.getSessionFactory());
}
My question: what is causing this error? The only configuration
document that gives me much information is the Hibernate search
documentation, which doesn't provide many more details relating to
getting this most basic scenario to work other than 'this is the
simple example, and the first step'. I'm also unclear on if I need to
put the post-commit event listeners in my
applicationContext-hibernate.xml file, and if I do what the right way
to do it is.
Thank you for the help.
Richard
17 years, 2 months
Hibernate Events/second level cache issue
by Ronen Yaari
All,
I am searching a way to do the following:
Hibernate before executing a query will access my hook class. If my hook
class returns an object this is the object that Hibernate should return
as the result of this query, if I return null the query will continue to
execute normally.
The motivation of doing this is. The second level cache works only on
objects PKs (moreover I think it calls the second level cache only for
PKs queries so even if I wrote my own second level cache implementation
it won't work). I want to be able to use a cache that enables me to use
it for non PKs queries. In this case I need to intercept the Hibernate
query before it happens, check my cache and return the object if it
exists and if not let hibernate continue his normal work.
I search the Interceptors/Events options and I did not found any
solution for above, did I missed something? , Any ideas?
Thanks,
Ronen
17 years, 3 months
(no subject)
by Walden Mathews
Hello,
I'm using Jboss-4.0.5-GA in the ejb3 configuration. I'm trying to
implement the following entities and relationships, without success:
Entity: Security
Entity: Trade
Entity: Allocation extends Trade
Security->Trade is one-to-many with Trade as the relationship owner
Trade->Security is many-to-one
Security->Allocation is one-to-one with Allocation as the relationship
owner
Allocation->Security is one-to-one
The basic idea is that while a Security may have a collection of Trades
associated with it, at most one can be an Allocation. And if a Security
has an associated Allocation, then that Allocation must appear in the
Trades collection of the Security as well.
I've tried this approach:
@Entity public class Security {
...
@OneToMany(mappedBy="security") public Collection<Trade>
getTrades() {...}
@OneToOne(mappedBy="security") public Allocation
getAllocation() {...}
}
@Entity public abstract class Trade {
...
@ManyToOne public Security getSecurity() {...}
}
@Entity public class Allocation extends Trade {...}
When I try to update (merge) an Allocation, the query and error I get
from Hibernate look like this:
Query:
[org.hibernate.SQL] select allocation0_.id as id9_10_, etc., ... where
allocation0_.security_id=? and allocation0_.DTYPE='alloc'
Error:
[org.hibernate.type.LongType] could not bind value '1st Lien Term Loan'
to parameter: 1; com.xyz.entity.Security
In the error message, '1st Lien Term Loan' is the toString() value of
the associated Security, not it's long getId() value, as I would have
expected.
I have also tried giving the one-to-one a different name on the owner
side:
@Entity public class Security {
...
@OneToMany(mappedBy="security") public Collection<Trade>
getTrades() {...}
@OneToOne(mappedBy="issue") public Allocation
getAllocation() {...}
}
@Entity public abstract class Trade {
...
@ManyToOne public Security getSecurity() {...}
}
@Entity public class Allocation extends Trade {
...
@OneToOne public Security getIssue() {
return super.getSecurity();
}
}
But the result is the same.
Does anyone know what the problem is here, or am I using the wrong
approach? Any pointers would be much appreciated.
Thanks,
wmathews(a)aladdincapital.com
17 years, 3 months