On Sunday, December 27, 2015 at 12:34:01 AM UTC+1, machak wrote:
>
> Hi Eric,
>
> On Saturday, December 26, 2015 at 11:20:33 PM UTC+1, Erik Pragt wrote:
>>
>>
>>> I haven't used Object database, but I would expect it needs a 
>>> proxy-entity, so you would probably need to fetch - update,
>>> see 
>>> http://orientdb.com/docs/2.0/orientdb.wiki/Object-2-Record-Java-Binding.html
>>> "
>>> You can save a POJO to the database by calling the method save(pojo). 
>>> If the POJO is already a proxied instance, then the database will just save 
>>> the record bounded to it. In case the object is not proxied the database 
>>> will serialize it and save the corresponded record: *In this case the 
>>> object MUST be reassinged with the one returned by the database*
>>> "
>>>
>>>
>> Hi /m,
>>
>> Thanks for the reply, but I've read the above 3 times now, and I still 
>> don't know what it means. I have no proxied object, just a normal POJO, so 
>> this should apply:
>>
>> "In case the object is not proxied the database will serialize it and 
>> save the corresponded record: *In this case the object MUST be 
>> reassinged with the one returned by the database"*
>> "In case the object is not proxied the database serialize it and save the 
>> corresponded record"...okay, I think I know what that means, cause that's 
>> what I'm trying, and then:
>> *"In this case the object MUST be reassinged with the one returned by the 
>> database"*....ehh...wot? In this case the object must be what? 
>> Reassinged? Reassigned? I unfortunately have no idea what it means.
>>
>> I think I have a simple use case: 
>> I want to create new Book, save it (create a new one in the db), change 
>> eg. the title, and save it again (ie updating the values). But the above 
>> text helps little in accomplishing that. I'll have a look at the fetching 
>> though (would that be the same as loading? (public <RET> RET load(final 
>> Object 
>> iPojo) 
>>
>> I have no idea what an iPojo is. Is says it's "the entity to load". But 
>> that's not really clear, especially when the code examples show only 
>> examples with rids: Animal animal = database.load(rid); (see 
>> http://orientdb.com/docs/2.0/orientdb.wiki/Object-Database.html). So, an 
>> iPojo is an rid??? I'm confused :)
>>
>> Cheers, Erik
>>
>>
>
> it is pretty simple:  
> you can create an object yourself (e.g. new Object()). That object is in 
> your control, none proxy one. Object you retrieve through orient entity 
> manager, is proxy one, backed by entity manager. 
> In second  case any value you change and you call save, changes will be 
> done on existing object: simply because object has an id (RID)...
> I don't know about "reassigned" description, but I guess, they mean 
> *values* need to be reassigned (copied over?) it is confusing. 
>
> In any case, what you should try is following:
>
> // save new object:
> MyObject *foo* = save(new MyObject());
> // update some properties:
> *foo*.setProperty("bar", "foobar")
> // update object
> save(*foo*);
>
>

ha, just saw, there is  a compete example with proxied objects (docs page):

// OPEN THE DATABASE
OObjectDatabaseTx db = new OObjectDatabaseTx 
("remote:localhost/petshop").open("admin", "admin");
// REGISTER THE CLASS ONLY ONCE AFTER THE DB IS OPEN/CREATED
db.getEntityManager().registerEntityClasses("foo.domain");
// CREATE A NEW PROXIED OBJECT AND FILL IT
Account account = db.newInstance(Account.class);
account.setName( "Luke" );
account.setSurname( "Skywalker" );

City rome =  db.newInstance(City.class,"Rome",  
db.newInstance(Country.class,"Italy"));
account.getAddresses().add(new Address("Residence", rome, "Piazza Navona, 1"));

db.save( account );
// CREATE A NEW OBJECT AND FILL IT
Account account = new Account();
account.setName( "Luke" );
account.setSurname( "Skywalker" );

City rome = new City("Rome", new Country("Italy"));
account.getAddresses().add(new Address("Residence", rome, "Piazza Navona, 1"));
// SAVE THE ACCOUNT: THE DATABASE WILL SERIALIZE THE OBJECT AND GIVE THE 
PROXIED INSTANCE
account = db.save( account );


 

> cheers
> /m
>
>
>
>>
>>
>>
>>
>>  
>>
>>> hth,
>>> cheers
>>> /m
>>>  
>>>
>>>>
>>>> Thanks, 
>>>>
>>>>
>>>> Erik
>>>>
>>>>
>>>>

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"OrientDB" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to