[hibernate-dev] [OGM-8, OGM-21] initial "criteria query" search
Cyrille Chépélov
cyrille at chepelov.org
Wed Aug 17 08:58:47 EDT 2011
Hi Sanne,
Le lundi 15 août 2011 à 16:48 +0100, Sanne Grinovero a écrit :
> Regarding queries, you can use it with Hibernate Search as we did in a
> demo at JBoss World [1], that doesn't provide all power of relational
> queries but can still deal with most needs (and full text queries as
> well); the only thing you have to consider is to use
Well; the application for which I'm experimenting with OGM/Infinispan
requires a synchronous search behaviour (which is, once a write
transaction completes, subsequent 'read' transactions must show
immediately the modified state). A previous implementation of the
service currently struggles, because it attempts to expect this from
SOLR (meep! wrong). Eventually relying on Lucene again won't buy me much
here :)
As both OGM-21 (no JP-QL) and OGM-8 (no Criteria Queries either) block
me, and before temporarily retreating on JPA(Hibernate)+Postgres, I've
played with sketching a very early implementation of CQ support. Not
much, not properly tested, nothing, but enough to get a my single use
case somewhat working:
/* with
@Entity
public class Document {
@Id
@GeneratedValue(generator = "uuid")
@GenericGenerator( name="uuid", strategy = "uuid2")
String internalUuid;
@NaturalId
private String docuid;
public String title;
}
*/
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<Document> cq = cb.createQuery(Document.class);
Root<Document> clRoot = cq.from(Document.class);
cq.select(clRoot).where(cb.equal(clRoot.get("docuid"), uid));
/* List<Document> docs = em.createQuery(cq).getResultsList(); */
List<Document> docs = TypedCriteriaQueryFactory
.createTypedQuery(em, cq).getResultList();
caveats:
* apparently, Infinispan's Distributed Execution Framework
requires the clustering mode to be "distribution"; "replication"
ought to be fine too, but the engine seems to have strong
opinion against this.
* only the simplest queries have a chance to work
* a full scan on the whole ENTITIES cache is going to happen on
every query. And then an individual load(by @Id) on each
matched entity.
* for the moment, this is implemented as external code, rather
than a proper patch. Hence a fairly ugly "ClandestineAccess"
class. I guess a more correct implementation will have to find a
better way to bounce from OgmEntityManager down to the
InfinispanDialect, but for now Session seems to have a fairly
strong opinion that the query world is about JDBC and HQL->SQL
translations only.
* Apparently, sometimes the ghost of a previous instance is
detected by Infinispan which then fails because of a remote
invocation error. I guess this is more an issue with eclipse
starting new sessions before killing the previous one.
With that said, I can now proceed!
-- Cyrille
More information about the hibernate-dev
mailing list