Thank you Werner and Bruce,

If this is the answer that "read-only" could only be used for simple
data types, yes than I would submit this as bug. 

I added below the code of my problem. As you have guessed, yes, I use
there the "DataBase.load()" feature. Does this make any difference as
using OQL queries? 

If you have any other suggestions how I could use my existing data model
with my "constant" objects 
please let me know. I think there must exist a solution for this common
problem, can't be that I am the first Castor JDO user which uses
constant objects, or do the others all hardcoding their categories ? ; )

regards 
Mark

>Mark,

>can you show me a short code fragment that shows me how you are
assigning a salutation 
>to a customer ? I am assuming that you are loading the 
>correct SalutationBean instance via e.g. Database.load (Class, Object),
correct ?

>Werner


JDO jdo = new JDO();
PrintWriter writer = new
com.bi.core.log.CastorLog4jProxy("org.exolag.jdo.JDO");
jdo.setLogWriter( writer );
jdo.setConfiguration( "src/config/db_config.xml");
jdo.setDatabaseName("bicore");
jdo.setAutoStore( true );

// Obtain a new database
Database db = jdo.getDatabase();
db.begin();
    
// getting constant object from database (sb is marked as read only in
the db config)
SalutationBean sb = (SalutationBean) db.load(SalutationBean.class,new
Long(1));                           

CustomerBean c = new CustomerBean();
c.setCompany("werken");
c.setFamilyName("Egloff");
c.setSurName("Mark");
c.setSalutation(sb);    
            
db.create(c);

db.commit();

db.close();     

-----

Mark Egloff wrote:


I have the following problem. I have in my data model some tables which
holds categories with other words constants which are not going never
Updated or deleted. An easy example for a better understanding:
Customer has a Salutation like "Mr.", "Ms." etc. Therefore I have table
"customer" and a table "salutation". The relation is single ended,
means only the customer knows about "his" salutation. So a foreign id is
stored in the customer record.
In order to achieve this data model I thought to use the "read-only"
feature of Castor.


Now If I like to create a new customer I would assign a salutation from
him. But If I do so I am getting the following exception:


org.exolab.castor.jdo.DuplicateIdentityException: Duplicate identity
found for object of type com.bi.core.entity.SalutationBean with identity
1: an object with the same identity already exists in persistent storage
        at
org.exolab.castor.jdo.engine.SQLEngine.create(SQLEngine.java:675)
        at
org.exolab.castor.persist.ClassMolder.create(ClassMolder.java:912)


Because the salutation is already existing. 

Now to my questions:

But why tries Castor to create a new one? Is the read-only feature not
yet supported in Castor or can I not use it this way to achieve my
target? Exists there other ways for using "constants" with Castor? 

...


         <field name="salutation"
type="com.bi.core.entity.SalutationBean">
            <sql name="salutation" read-only="true"/>
        </field>


Mark,

It looks as though the read-only attribute for <field> elements only
works with primitive types. Because the field that is specified to be
read-only above is a complex type, Castor JDO is behaving as designed.
I'm not quite sure why this was designed in this manner exactly. But I
hazard a guess that making a complex type read-only was either not
desirable or it could cause issues during commit. If this is something
you'd like to be changed, please file a Bugzilla
(http://bugzilla.exolab.org/) report with a severity of 'Enhancement.'

Bruce
--
perl -e 'print unpack("u30","<0G)[EMAIL
PROTECTED]&5R\"F9E<G)E=\$\!F<FEI+F-O;0\`\`");'


The Castor Project
http://www.castor.org/


Apache Geronimo
http://incubator.apache.org/projects/geronimo.html

----------------------------------------------------------- 
If you wish to unsubscribe from this mailing, send mail to
[EMAIL PROTECTED] with a subject of:
        unsubscribe castor-dev

Reply via email to