Grails GORM MongoDB. Issue with parent model classes - mongodb

Background: I am using the GORM plugin for MongoDB in Grails.
Problem:Say that I have two domain classes A and B. B extends A. If I execute B.save() the plugin will create a collection named A in MongoDB. What am I supposed to do to get the plugin to create the collection B?
Many Thanks,
Alex

It should create collection B in the database.
Can you provide more info, definition of A and B classes?

Related

Inserting into MongoDB using Spring Data inserts into two Collections

I'm creating a Spring Boot application that is inserting objects into a MongoDB database. The problem is that when I'm doing the insert it is creating records in two collections. Basically I have a POJO A and POJO B that extends A. When the insert happens it creates documents in both collection A and collection B for the same ObjectId. My expectation was that it would only create documents in collection B for POJO B as that is what is being passed into the repository.insert method. What am I doing wrong? I can provide configurations and version numbers if needed. Also, I am using Groovy if that makes a difference.
The answer was based on my application and therefore an issue that I introduced. I'm using Spring Batch and using the MongoReader and MongoWriter. I'm reading from collection "a" and I expected the writer to write back to collection "a" but inside of the processor I'm converting the object to POJO B and because I'm not specifying the collection then the MongoWriter determines the collection based on the class and creates collection "b". I added the same Document annotation to both classes and that resolved the issue.

Does Doctrine 2.5 has an alternative to JPA #ElementCollection?

Doctrine 2.5 has embedded objects feature, but what I am looking is a collection of these objects like Java Persistence API has. Basically, an annotation #ElementCollection is what I am looking for doctrine.
Looks like Doctrine had such functionality developed in 2.2 version, but is it left over or what?
Doctrine 2.5 does not support multiple embedded objects yet.
But you have following alternative solutions :
Serialising a collection of embedded objects into a single column
Map them as entity and one-to-many relationship but use OO to enforce the embedded object 's characteristic.For example , to well encapsulate them such that its lifecycle and behaviour can only be managed by its parent.
Reference:
Domain-Driven Design in PHP - Persisting a Collection of Value Objects
Persisting Value Objects in Doctrine

playframework2 how to open multi-datasource configuration with jpa

i want to configure multiple datasources in Play framework 2.1 with jpa.
one is H2, and the other is Oracle.
so i added the code like this in application.conf:
db.default.driver=org.h2.Driver
db.default.url="jdbc:h2:file:E:/myproject/setup/db/monitor"
db.default.user=sa
db.default.password=sa
db.default.jndiName=DefaultDS
jpa.default=defaultPersistenceUnit
db.oracle.driver=oracle.jdbc.driver.OracleDriver
db.oracle.url="jdbc:oracle:thin:#10.1.20.10:1521:prjct"
db.oracle.user=LOG_ANALYSE
db.oracle.password=LOG_ANALYSE
db.oracle.jndiName=OracleDS
jpa.oracle=ojdbcPersistenceUnit
i don't know how to assign for jpa.oracle and give it a meaningless name. but it does not show any errors. should i change it and how?
the main problem is: how can i tell Play which entities are managed by default datasource what others by the other, oracle?
for example, class A, B's tables are in H2 and class C, D's tables are in oracle. what should i codding for these entities to assign the datasources?
Finally, i found the way to connect to different db sources.
in play, the api of jpa has no method named getJPAConfig("").
thers is another construction of em(), em("").
so i access the dbs as:
EntityManager em0 = JPA.em("default");
EntityManager em1 = JPA.em("oracle");
that's it!
I did not used this feature (yet) but you have to useone of the annotations on your Models:
#PersistenceUnit(name="default")
#PersistenceUnit(name="oracle")
Or when you query yourself you can alsow specify it as:
EntityManager em = JPA.getJPAConfig("oracle").em();

Yii Gii with MongoDB

Could anyone please tell me how MongoDB can be used with YII?
How can we create controller and model functions using Gii if the database used is MongoDB?
I've used YiiMongoDBSuite (YMDS), which has some very rough support for Gii. You can generate starter classes, but given that MongoDB does not have a fixed schema you will need to edit the model to make them useful. There is an odd kludge that lets you generate MongoDB models from a SQL table, but this seems more effort than it's worth.
YMDS' EMongoDocument class extends the standard Yii CModel class, so this is a useful base if you want to build apps with CRUDS.
The unfortunate caveat is that YMDS is no longer maintained by the original author, and there are a few community forks to chose between.
The way of creating controllers is same as usual but you have to use an extension to talk to mongoDB from Yii ,
You need to use direct Mongo suite of yii . It is an extension which has a collection of components for the mongoDB .

GWT RequestFactory entity type initialization

I was looking over the DynatableRF example and I was wondering why in SummaryWidget when you create a new Person instance the subfields like address and schedule are not auto-populated. Is there a better way than to manually instantiate a new instance of every non-primitive subfield down the tree?
The framework can't auto-populate subfields because it won't know if you want instances in those fields or you want them to be null. You want different things in different circumstances.
It sounds like what you are asking for is Dependency Injection in which case the GIN (GWT INjection) project can help.