Jan 27th, 2011, 02:33 PM
spring-data-mongodb improvement idea
today i started to integrate the snapshot of spring-data-mongodb into a new project.
looks very promising
i was not sure if i should go with morphia or spring data, but i think i choose the right framework
one thing i came across which i don't like.
in my spring xml, which is really great, i really like that i don't have to write my own MongoRepository implementations.
but i would really like to use one mongo db collection foreach entity.
correct my if i'm wrong, MongoRepositoryFactoryBean gets the one MongoTemplate which i have defined in xml, i set no defaultCollectionName, and so i can't use the MongoRepository interface, because getRequiredDefaultCollectionName of MongoTemplate will throw an exception.
i see 2 solutions/hacks to workaround this problem.
define a mongotemplate bean foreach collection and also each repository with
(btw, why the additional mongo- prefix? the other elements in the mongo namespace does not have this prefix )
2nd: i could extend
to create my own factory, which uses the template property to create a new template with the defaultCollectonName of domainClass.getSimpleType() in the getTargetRepository method
i prefer the 2nd, but i still feels like a hack.
i attached a patch (not tested, maybe not even compilable ) for possible solution, but maybe you have a better idea
if you also see this as an improvent it would be great if someone of the team would put this issue into jira, and maybe i could find its way into the mongo m1 release?
edit: ok extending MongoRepositoryFactory is useless because template is private :-/, i still could implement RepositoryFactorySupport, but this means even more hack code :-/
edit again: ok this also does not work because i can't access the mongo template properties which i need to create a new instance by public getters :-/, so i think i will have to go with xml configuration until another solution is available
Last edited by christoph.e; Jan 27th, 2011 at 02:43 PM.
Jan 28th, 2011, 02:04 AM
maybe i should turn this into a simple question
is or will it be possible to use mongo repositories which have their own default collection name, for example the name of the domain class?
Jan 28th, 2011, 01:14 PM
I also felt the same need, to be able to specify the collection name for each repository. +1 for the suggestion to incorporate this into the project. The collection name used for each entity should be specifiable as an annotation, e.g., the Table annotation.
Another important enabler for using spring-data-mongo in production code is to add a few annotations which have similar functionality to the @Reference, @Embedded etc. in Morphia, and for naming the fieldnames in the persistence store differently from the fieldnames used in the Java Entity. Of course these annotations should be consistent with JPA annotations, and should be a superset of JPA annotations.
Feb 10th, 2011, 12:53 PM
I just changed the repository and query implementation to use the simple domain class for now . As long as we're lacking more sophisticated mapping options. Could one of you please file a ticket for this?
 - https://github.com/SpringSource/spri...ff7063781fb507
Last edited by Oliver Gierke; Feb 10th, 2011 at 01:14 PM.
Feb 11th, 2011, 03:50 PM
I have already created a JIRA ticket,
Add support for specifying attributes to entities, e.g., collection name, field names, etc.
Feb 15th, 2011, 04:19 PM
Thank you for the job done.
I'd like to see coming the annotation support as morphia did (modulo JPA annotations).
Currently, Morphia has addressed the type safety issue. This allows for easy mapping of objects from and to MongoDB along with a query interface.
For my understanding, is it the intention of the present effort to cover the same level of features as Morphia did (cf. DATADOC-40)?
Mar 17th, 2011, 11:11 AM
There will be quite the overlap in features with Mophia and of course we will add features which we can use from the Spring Framework, such as the Spring Expression Language, ApplicationContextEvents, AOP, and general integration points such as Data Access Exception hierarchy.
Just so you know, I had a meeting with Scott Hernandez (Morphia author who now works at 10gen) last week for a few hours to talk about the Spring Mongo work. (We have been in contact with 10gen quite a lot over the months and have a great working relationship). Some mapping support will eventually get into the Java driver provided from 10gen - as it is now with the C#/.NET driver. Hopefully we can align efforts/codebase to some extent so that there is portability with annotations as this whole mapping area gets more mature.
Future directions we will go with mapping is to use the work done at part of the 'GORM for NoSQL' (Spring Data Mapping under the covers)work that allows for persistence by reachability, so you don't have to explicitly manage parent/child objects, cleaning up references when deleting objects, a batch scope (queue up inserts/deletes).
Last edited by Mark Pollack; Mar 17th, 2011 at 11:17 AM.