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.