That could be an option; file an issue and get some votes for it, or supply
a patch.
It shouldn't be too hard support, but I'm not sure about mapping between
the two annotation systems.
For more information:
http://code.google.com/p/morphia/wiki/QuickStart
Is it possible not to save the className into the object - it wrecks
obvious havock on refactoring? Apologies if the answer is already
documented somewhere - couldn't find it ...
carnatus, there is an attribute on the annotation to do that,
@Entity(noClassnameStored=True); It has to be explicit because the
className field is used for resolving collections that contain multiple
types.
Scott, thanks a million, my bad! Do you guys need help with the
documentation at all?
carnatus, we always need help on docs. Join the list
(http://groups.google.com/group/morphia) and ask again there. These
comments are not the best place to chat.
In the persisting POJOs segment, how does Morphia know that 'address'
belongs to 'hotel'? Is there a hotel.setAddress(address); missing?
For more information:
https://code.google.com/p/morphia/wiki/QuickStart
Morphia looks at the fields and persists them. The Hotel class has a field
called address of type Address. Getters and Setters are not used for
persistence.
I have the same requirement of saving these kind of objects in MongoDB. How
can I do this in C#?
chsrinu, the mongodb csharp driver should do this, most of it at least.
why I used mapPackage (code : morphia.mapPackage("domain");), the morphia
(code: datastore.ensureIndexes();) don't create index for mongo ? (unless I
use map(class))
"In the persisting POJOs segment, how does Morphia know that 'address'
belongs to 'hotel'? Is there a hotel.setAddress(address); missing?"
Scott, I don't understand your answer - from the code shown here, hotel
doesn't have any reference to the address! Address and hotel are just 2
separate objects that have been created... What if there were 2 addressed
defined, how would Morphia know which one to use?
ie.
Hotel hotel = new Hotel();
hotel.setName("My Hotel");
Address address = new Address();
address.setStreet("123 Some street");
Address address1 = new Address();
address1.setStreet("456 Some street");
Morphia morphia = ...;
Datastore ds = morphia.createDatastore("testDB");
// Save the POJO
ds.save(hotel);
Which address is hotel going to be associated with? There must be a
setAddress call somewhere no?
Yes, I have added the setAddress; sorry for the confusion and thanks for
catching that.
I missed the point of that question; we all have bad days and that was
clearly one of mine :(
The 'Prepare the framework' section should be updated as the constructor
and method signatures do not match the .99 API and will not compile. Should
update to:
...
Morphia morphia = new Morphia( );
morphia.map(Hotel.class).map(Address.class);
Datastore ds = morphia.createDatastore( new Mongo(), "my_database" );
...
Typo: `import com.google.code.morphia.dao.DAO` should be replaced with
`import ...dao.BasicDAO` --- or vice, versa: `BasicDAO<Hotel, String>`
should be replaced with `DAO<Hotel, String>`.
"import com.google.code.morphia.annotations.CollectionName; " where
is "CollectionName" class?
what about the performance? if I want load 1000 records and present in
front end, mapping to 1000 objects will slow. In this case I prefer to load
the record direct from mango and give them to front end.