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 Rob Kischuk <RK...@sprich.com> on 2003/06/19 15:57:52 UTC
Caching/store bug?
I'm using OJB 1.0rc3, and running into a rather vexing caching issue - I'm
hoping someone else can shed some light on the issue. I'm executing the
following code:
CollectionItemService service = CollectionItemService.getInstance();
CollectionItem item = service.findById( collectionItemId );
item.setAssignedDC( 0 );
item.setState( CollectionItem.STATE_UNASSIGNED );
log.info("*** Collection item has ID " + item.getId() );
log.info("*** Assigned DC is " + item.getAssignedDC() );
service.clearCache();
service.store( item );
log.info("*** Collection item has ID " + item.getId() );
log.info("*** Assigned DC is " + item.getAssignedDC() );
and the service methods look like this:
protected CollectionItemService()
{
broker = PersistenceBrokerFactory.defaultPersistenceBroker();
}
public static CollectionItemService getInstance()
{
return new CollectionItemService();
}
public void store( CollectionItem c ) {
broker.beginTransaction();
broker.store( c );
broker.commitTransaction();
broker.close();
}
public CollectionItem findById( String collectionItemId )
{
Criteria crit = new Criteria();
crit.addEqualTo("id", collectionItemId);
Query query = new QueryByCriteria( CollectionItem.class, crit );
return (CollectionItem) broker.getObjectByQuery( query );
}
The debug statements before I call store output:
*** Collection item has ID 1
*** Assigned DC is 0
and after store, the output is:
*** Collection item has ID 1
*** Assigned DC is 1 (This was the value prior to setAssignedDC)
I find it rather vexing that somehow, the broker.store() seems to be
changing the state of the object I am storing. I see the parameterized
update statement being properly generated by the SqlGenerator, but the
database is also not being properly updated. Can anyone shed some light on
this problem?
-Rob
Re: Caching/store bug?
Posted by Thomas Mahler <th...@web.de>.
IMO this has nothing to do with caching.
the store method itself seems to modify the instance without any
interference of the cache.
Maybe you have defined autoincrement="true" for the assigneDC attribute?
Or did you set locking="true" on this field?
cheers,
Thomas
Rob Kischuk wrote:
>
>
> I'm using OJB 1.0rc3, and running into a rather vexing caching issue - I'm
> hoping someone else can shed some light on the issue. I'm executing the
> following code:
>
>
>
> CollectionItemService service = CollectionItemService.getInstance();
>
> CollectionItem item = service.findById( collectionItemId );
>
> item.setAssignedDC( 0 );
>
> item.setState( CollectionItem.STATE_UNASSIGNED );
>
> log.info("*** Collection item has ID " + item.getId() );
>
> log.info("*** Assigned DC is " + item.getAssignedDC() );
>
> service.clearCache();
>
> service.store( item );
>
> log.info("*** Collection item has ID " + item.getId() );
>
> log.info("*** Assigned DC is " + item.getAssignedDC() );
>
>
>
> and the service methods look like this:
>
>
>
> protected CollectionItemService()
>
> {
>
> broker = PersistenceBrokerFactory.defaultPersistenceBroker();
>
> }
>
>
>
> public static CollectionItemService getInstance()
>
> {
>
> return new CollectionItemService();
>
> }
>
>
>
> public void store( CollectionItem c ) {
>
> broker.beginTransaction();
>
> broker.store( c );
>
> broker.commitTransaction();
>
> broker.close();
>
> }
>
>
>
> public CollectionItem findById( String collectionItemId )
>
> {
>
> Criteria crit = new Criteria();
>
> crit.addEqualTo("id", collectionItemId);
>
> Query query = new QueryByCriteria( CollectionItem.class, crit );
>
> return (CollectionItem) broker.getObjectByQuery( query );
>
> }
>
>
>
> The debug statements before I call store output:
>
> *** Collection item has ID 1
>
> *** Assigned DC is 0
>
>
>
> and after store, the output is:
>
>
>
> *** Collection item has ID 1
>
> *** Assigned DC is 1 (This was the value prior to setAssignedDC)
>
>
>
> I find it rather vexing that somehow, the broker.store() seems to be
> changing the state of the object I am storing. I see the parameterized
> update statement being properly generated by the SqlGenerator, but the
> database is also not being properly updated. Can anyone shed some light on
> this problem?
>
>
>
> -Rob
>
>