`Single Proxy for a Whole Collection` problem

2004-01-08 Thread Andrei Ivanov

Hello,
I've created a mapping like this:

class-descriptor
class=com.ines.flanco.model.ProductTO
table=products

field-descriptor
name=id
column=id
jdbc-type=INTEGER
nullable=false
primarykey=true
autoincrement=true
sequence-name=products_id_seq
/
field-descriptor
name=name
column=name
jdbc-type=VARCHAR
nullable=false
/
collection-descriptor
name=symbols
element-class-ref=com.ines.flanco.model.SymbolTO
proxy=true
auto-update=true
auto-delete=true
indirection-table=products_symbols
fk-pointing-to-this-class column=product/
fk-pointing-to-element-class column=symbol/
/collection-descriptor
/class-descriptor

And created the objects:

public class ProductTO implements java.io.Serializable {

protected int id;
protected String name;
protected Vector symbols;

getters and setters...

public void setSymbols(Vector symbols){
this.symbols = new Vector(symbols);
}
public Vector getSymbols(){
return symbols;
}
}

public class SymbolTO implements java.io.Serializable {

protected int id;
protected String name;
protected String description;

getters and setters...
}

If I don't use the proxy feature for the collection everything is fine.

My problem is that I get an exception when I mark it as a proxy:

[PersistentField] ERROR: while set field:
object class[ com.ines.flanco.model.ProductTO
target field: symbols
target field type: class java.util.Vector
object value class: org.apache.ojb.broker.accesslayer.ListProxy
object value: [EMAIL PROTECTED]
null
java.lang.IllegalArgumentException
at 
sun.reflect.UnsafeObjectFieldAccessorImpl.set(UnsafeObjectFieldAccessorImpl.java:63)
at java.lang.reflect.Field.set(Field.java:519)
at 
org.apache.ojb.broker.metadata.fieldaccess.PersistentFieldDirectAccessImpl.doSet(Unknown
 
Source)
at 
org.apache.ojb.broker.metadata.fieldaccess.AbstractPersistentField.set(Unknown 
Source)
.

2004-01-08 16:46:59 StandardWrapperValve[action]: Servlet.service() for 
servlet action threw exception
org.apache.ojb.broker.metadata.MetadataException: Error setting 
field:symbols in object:com.ines.flanco.model.ProductTO
at 
org.apache.ojb.broker.metadata.fieldaccess.PersistentFieldDirectAccessImpl.doSet(Unknown
 
Source)
at 
org.apache.ojb.broker.metadata.fieldaccess.AbstractPersistentField.set(Unknown 
Source)
at 
org.apache.ojb.broker.core.QueryReferenceBroker.retrieveCollection(Unknown 
Source)
at 
org.apache.ojb.broker.core.QueryReferenceBroker.retrieveCollections(Unknown 
Source)



Can you please tell me what I did wrong ?

Thank you.

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



RE: `Single Proxy for a Whole Collection` problem

2004-01-08 Thread oliver . matz
Hello,

 public class ProductTO implements java.io.Serializable {
 
 protected int id;
 protected String name;
 protected Vector symbols;

'Vector' is not a good idea.  You should use an interface
type such as Collection or List for the type declaration ...

 getters and setters...

... and also for the parameter and return types.

 My problem is that I get an exception when I mark it as a proxy:
 
 [PersistentField] ERROR: while set field:
 object class[ com.ines.flanco.model.ProductTO
 target field: symbols
 target field type: class java.util.Vector
 object value class: org.apache.ojb.broker.accesslayer.ListProxy

This is a good error message, isn't it?
The proxy is of type ListProxy, which implements the List interface
but is not assignable to a field of type Vector.


HTH,
Olli
-- 
  Oliver Matz
  ppi Media GmbH
  Deliusstraße 10
  D-24114 Kiel
  phone +49 (0) 43 1-53 53-422
  fax   +49 (0) 43 1-53 53-2 22
  email mailto:[EMAIL PROTECTED]
  web   www.ppi.de

Explore your printnet!

DRUPA 2004
Düsseldorf, Germany, 6 - 19 May 2004, Booth 6E62


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



RE: `Single Proxy for a Whole Collection` problem

2004-01-08 Thread oliver . matz
Hello,

 -Original Message-
 From: Andrei Ivanov [mailto:[EMAIL PROTECTED]

 I see here 
 http://java.sun.com/j2se/1.4.2/docs/api/java/util/Vector.html 
 that Vector implements the List interface, and I used Vector because it's 

that means that you can assign a Vector to a field of type List,
but not vice versa.

 in the ojb documentation: 

 The association is implemented by the Vector attribute allArticlesInGroup

 on the ProductGroup class.


http://db.apache.org/ojb/tutorial3.html#Using%20a%20Single%20Proxy%20for%20a
%20Whole%20Collection

In that example, no proxies are used for that collection.
If I had written these classes, I would have used interface types
in the declarations and ArrayList for the instantiation.
There is a performance advantage of ArrayList against Vector,
because access to elements is synchronized in Vector.

To sum up: Vector is evil.

Olli

-- 
  Oliver Matz
  ppi Media GmbH
  Deliusstraße 10
  D-24114 Kiel
  phone +49 (0) 43 1-53 53-422
  fax   +49 (0) 43 1-53 53-2 22
  email mailto:[EMAIL PROTECTED]
  web   www.ppi.de

Explore your printnet!

DRUPA 2004
Düsseldorf, Germany, 6 - 19 May 2004, Booth 6E62


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]