You are viewing a plain text version of this content. The canonical link for it is here.
Posted to ojb-user@db.apache.org by Abid Hussain <ab...@abid76.de> on 2006/10/11 16:35:39 UTC
store collections
Hi everybody,
I want to implement a method which stores not only one object but a
collection of objects.
I tried this one:
public void storeAll(Collection valueObjects) {
if (valueObjects != null) {
broker.beginTransaction();
for (Iterator i = valueObjects.iterator(); i.hasNext();)
Object valueObject = i.next();
broker.store(valueObject, ObjectModification.INSERT);
}
broker.commitTransaction();
}
...but it doesn't work, not one object is stored into the database.
Anybody got an idea?
Regards,
Abid
--
Abid Hussain
Mail: abid.hussain@abid76.de
Web: http://www.abid76.de
---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org
Re: store collections
Posted by Armin Waibel <ar...@apache.org>.
Abid Hussain wrote:
> Hi Armin,
>
>> How can it happen that you try to insert ojb-proxied objects? If the
>> proxy object isn't materialized OJB assume that nothing has changed
>> and skip the store.
> Because I wanted to copy values from one database to another. So I first
> retrieved the values from the local DB and then tried to store them in
> the live-system DB.
>
> But when the problem only comes up with proxied objects then it is all
> right, I then just let the object being materialized by using the
> debug()-method and then copy it.
If you call object.hashCode() the object should be materialized too.
> Like Josef said, the code seems to be ok.
>
yep!
regards,
Armin
> Thanks a lot for quick help.
>
> Best regards,
>
> Abid
>
>>
>>> Because, when I change the code to this:
>>> public void storeAll(Collection valueObjects) {
>>>
>>> if (valueObjects != null) {
>>> broker.beginTransaction();
>>> for (Iterator i = valueObjects.iterator(); i.hasNext();)
>>> Object valueObject = i.next();
>>> --> logger.debug(valueObject);
>>> broker.store(valueObject, ObjectModification.INSERT);
>>> }
>>> broker.commitTransaction();
>>> }
>>> ...it works because the object is loaded from the database when
>>> calling the debug()-method.
>>> It seems that the broker has nothing to store in the method without
>>> the logging-statement seen below.
>>>
>>> But is there any other way to solve this problem?
>>>
>>> Regards,
>>>
>>> Abid
>>>
>>> Abid Hussain schrieb:
>>>> Hi everybody,
>>>>
>>>> I want to implement a method which stores not only one object but a
>>>> collection of objects.
>>>> I tried this one:
>>>> public void storeAll(Collection valueObjects) {
>>>>
>>>> if (valueObjects != null) {
>>>> broker.beginTransaction();
>>>> for (Iterator i = valueObjects.iterator(); i.hasNext();)
>>>> Object valueObject = i.next();
>>>> broker.store(valueObject, ObjectModification.INSERT);
>>>> }
>>>> broker.commitTransaction();
>>>> }
>>>> ...but it doesn't work, not one object is stored into the database.
>>>>
>>>> Anybody got an idea?
>>>>
>>>> Regards,
>>>>
>>>> Abid
>>>>
>>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
>> For additional commands, e-mail: ojb-user-help@db.apache.org
>>
>>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org
Re: store collections
Posted by Abid Hussain <ab...@abid76.de>.
Hi Armin,
> How can it happen that you try to insert ojb-proxied objects? If the
> proxy object isn't materialized OJB assume that nothing has changed and
> skip the store.
Because I wanted to copy values from one database to another. So I first
retrieved the values from the local DB and then tried to store them in
the live-system DB.
But when the problem only comes up with proxied objects then it is all
right, I then just let the object being materialized by using the
debug()-method and then copy it.
Like Josef said, the code seems to be ok.
Thanks a lot for quick help.
Best regards,
Abid
>
>> Because, when I change the code to this:
>> public void storeAll(Collection valueObjects) {
>>
>> if (valueObjects != null) {
>> broker.beginTransaction();
>> for (Iterator i = valueObjects.iterator(); i.hasNext();)
>> Object valueObject = i.next();
>> --> logger.debug(valueObject);
>> broker.store(valueObject, ObjectModification.INSERT);
>> }
>> broker.commitTransaction();
>> }
>> ...it works because the object is loaded from the database when
>> calling the debug()-method.
>> It seems that the broker has nothing to store in the method without
>> the logging-statement seen below.
>>
>> But is there any other way to solve this problem?
>>
>> Regards,
>>
>> Abid
>>
>> Abid Hussain schrieb:
>>> Hi everybody,
>>>
>>> I want to implement a method which stores not only one object but a
>>> collection of objects.
>>> I tried this one:
>>> public void storeAll(Collection valueObjects) {
>>>
>>> if (valueObjects != null) {
>>> broker.beginTransaction();
>>> for (Iterator i = valueObjects.iterator(); i.hasNext();)
>>> Object valueObject = i.next();
>>> broker.store(valueObject, ObjectModification.INSERT);
>>> }
>>> broker.commitTransaction();
>>> }
>>> ...but it doesn't work, not one object is stored into the database.
>>>
>>> Anybody got an idea?
>>>
>>> Regards,
>>>
>>> Abid
>>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
> For additional commands, e-mail: ojb-user-help@db.apache.org
>
>
--
Abid Hussain
Mail: abid.hussain@abid76.de
Web: http://www.abid76.de
---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org
Re: store collections
Posted by Armin Waibel <ar...@apache.org>.
Hi Abid,
Abid Hussain wrote:
> Hi again,
>
> I forgot to tell that the problem seems to have to do with the using of
> proxies.
How can it happen that you try to insert ojb-proxied objects? If the
proxy object isn't materialized OJB assume that nothing has changed and
skip the store.
regards,
Armin
> Because, when I change the code to this:
> public void storeAll(Collection valueObjects) {
>
> if (valueObjects != null) {
> broker.beginTransaction();
> for (Iterator i = valueObjects.iterator(); i.hasNext();)
> Object valueObject = i.next();
> --> logger.debug(valueObject);
> broker.store(valueObject, ObjectModification.INSERT);
> }
> broker.commitTransaction();
> }
> ...it works because the object is loaded from the database when calling
> the debug()-method.
> It seems that the broker has nothing to store in the method without the
> logging-statement seen below.
>
> But is there any other way to solve this problem?
>
> Regards,
>
> Abid
>
> Abid Hussain schrieb:
>> Hi everybody,
>>
>> I want to implement a method which stores not only one object but a
>> collection of objects.
>> I tried this one:
>> public void storeAll(Collection valueObjects) {
>>
>> if (valueObjects != null) {
>> broker.beginTransaction();
>> for (Iterator i = valueObjects.iterator(); i.hasNext();)
>> Object valueObject = i.next();
>> broker.store(valueObject, ObjectModification.INSERT);
>> }
>> broker.commitTransaction();
>> }
>> ...but it doesn't work, not one object is stored into the database.
>>
>> Anybody got an idea?
>>
>> Regards,
>>
>> Abid
>>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org
Re: store collections
Posted by Abid Hussain <ab...@abid76.de>.
Hi again,
I forgot to tell that the problem seems to have to do with the using of
proxies.
Because, when I change the code to this:
public void storeAll(Collection valueObjects) {
if (valueObjects != null) {
broker.beginTransaction();
for (Iterator i = valueObjects.iterator(); i.hasNext();)
Object valueObject = i.next();
--> logger.debug(valueObject);
broker.store(valueObject, ObjectModification.INSERT);
}
broker.commitTransaction();
}
...it works because the object is loaded from the database when calling
the debug()-method.
It seems that the broker has nothing to store in the method without the
logging-statement seen below.
But is there any other way to solve this problem?
Regards,
Abid
Abid Hussain schrieb:
> Hi everybody,
>
> I want to implement a method which stores not only one object but a
> collection of objects.
> I tried this one:
> public void storeAll(Collection valueObjects) {
>
> if (valueObjects != null) {
> broker.beginTransaction();
> for (Iterator i = valueObjects.iterator(); i.hasNext();)
> Object valueObject = i.next();
> broker.store(valueObject, ObjectModification.INSERT);
> }
> broker.commitTransaction();
> }
> ...but it doesn't work, not one object is stored into the database.
>
> Anybody got an idea?
>
> Regards,
>
> Abid
>
--
Abid Hussain
Mail: abid.hussain@abid76.de
Web: http://www.abid76.de
---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org
Re: store collections
Posted by Josef Wagner <jo...@on-ergy.de>.
Hello Abid,
your code is o.k.
Does it work with storing one object allready?
valueObjects is != null :o) ?
have you debugged this width setting breakpoints?
I see no problem, why it shouldn`t work.
regrads
Josef
Abid Hussain schrieb:
> Hi everybody,
>
> I want to implement a method which stores not only one object but a
> collection of objects.
> I tried this one:
> public void storeAll(Collection valueObjects) {
>
> if (valueObjects != null) {
> broker.beginTransaction();
> for (Iterator i = valueObjects.iterator(); i.hasNext();)
> Object valueObject = i.next();
> broker.store(valueObject, ObjectModification.INSERT);
> }
> broker.commitTransaction();
> }
> ...but it doesn't work, not one object is stored into the database.
>
> Anybody got an idea?
>
> Regards,
>
> Abid
>
--
Josef Wagner
On Ergy Systemberatung GmbH
Füssener Str. 31
87459 Pfronten
Tel.: 08363 92898 - 57
Fax.: 08363 92898 - 51
E-Mail: j.wagner@on-ergy.de
---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org