-->
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.  [ 2 posts ] 
Author Message
 Post subject: MongoDB & Queries
PostPosted: Fri Apr 05, 2013 11:56 am 
Newbie

Joined: Tue Oct 18, 2005 1:52 pm
Posts: 1
We are beginning to integrate Hibernated OGM/Mongo into our existing application, have some basic insertions working, yay.

Now, when it comes to getting stuff out, I read the part about using Hibernate search or the native java drivers. We currently use the native java drivers.

Documentation states that the drawback of using the native java drivers is we get back the raw mongo docs and not managed entities.

That's fine with us for now, but I"m wondering if there is any way we could then hook into hibernate/ogm/mongo dialect, whereever, and get the system to perform the mongo -> jpa entity mapping.

This would be extremely helpful.

Also, wondering what sort of timeline there is for a more production-worth ogm jp-ql implementation?


Top
 Profile  
 
 Post subject: Re: MongoDB & Queries
PostPosted: Mon Apr 08, 2013 9:46 am 
Hibernate Team
Hibernate Team

Joined: Fri Sep 09, 2011 3:18 am
Posts: 295
Hi robatsu,
the mass indexer needs to do the same thing: retrieve the tuple objects from the datastore convert them to entities and then index them.

In the method MondoDBDialect#forEachTuple(...) a com.mongodb.DBCollection is returned and then converted into a Tuple using:
Code:
DBCollection collection = db.getCollection( entityKeyMetadata.getTable() );
for ( DBObject dbObject : collection.find() ) {
   consumer.consume( new Tuple( new MassIndexingMongoDBTupleSnapshot( dbObject, entityKeyMetadata ) ) );
}


To see how to obtain the metada you can check BatchIndexingWorkspace#metadata(...)
Code:
private EntityKeyMetadata metadata(SessionFactory sessionFactory, Class<?> indexedType) {
   OgmEntityPersister persister = (OgmEntityPersister) ( (SessionFactoryImplementor) sessionFactory ).getEntityPersister( indexedType.getName() );
   return new EntityKeyMetadata( persister.getTableName(), persister.getRootTableIdentifierColumnNames() );
}


At some point the consumer will convert the tuple into an enity, the logic is in the method TupleIndexer#entity(...):
Code:
private Object entity(Session session, Tuple tuple) {
   OgmEntityPersister persister = (OgmEntityPersister) ( (SessionFactoryImplementor) sessionFactory ).getEntityPersister( indexedType.getName() );
   OgmLoader loader = new OgmLoader( new OgmEntityPersister[] { persister } );
   List<Tuple> tuples = new ArrayList<Tuple>();
   tuples.add( tuple );
   OgmLoadingContext ogmLoadingContext = new OgmLoadingContext();
   ogmLoadingContext.setTuples( tuples );
   List<Object> entities = loader.loadEntities( (SessionImplementor) session, LockOptions.NONE, ogmLoadingContext );
   return entities.get( 0 );
}


I hope this can help.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.