Werner,
Sorry!!
Here are the code fragments:
CounterType and CounterVar are simple classes that just have the get & set
methods as described in the mapping file below:
<mapping>
<!-- Mapping for CounterType table -->
<class name="CounterType"
identity="id" access="read-only"
key-generator="IDENTITY">
<cache-type type="none" />
<map-to table="COUNTER_TYPE" />
<field name="id" type="integer" >
<sql name="counter_type_id" type="integer"
read-only="true"/>
</field>
<field name="description" type="string">
<sql name="counter_type_desc" type="varchar"
read-only="true"/>
</field>
</class>
<!-- Mapping for Counter table -->
<class name="CounterVar"
identity="id" key-generator="IDENTITY">
<cache-type type="none" />
<map-to table="COUNTER_VAR" />
<field name="id" type="integer" >
<sql name="counter_var_id" type="integer"/>
</field>
<field name="number" type="integer" >
<sql name="counter_var_number" type="integer"/>
</field>
<field name="type" type="CounterType">
<sql name="counter_var_type" />
</field>
</class>
</mapping>
below is the DB schema and some sample inserts:
drop DATABASE IF EXISTS TEST;
create DATABASE TEST;
use TEST;
create table TEST.COUNTER_TYPE
(
COUNTER_TYPE_ID INTEGER NOT NULL auto_increment,
COUNTER_TYPE_DESC VARCHAR(50) NOT NULL,
PRIMARY KEY (COUNTER_TYPE_ID)
)
type=Innodb;
INSERT INTO TEST.COUNTER_TYPE (COUNTER_TYPE_DESC) VALUES ("Type1");
INSERT INTO TEST.COUNTER_TYPE (COUNTER_TYPE_DESC) VALUES ("Type2");
INSERT INTO TEST.COUNTER_TYPE (COUNTER_TYPE_DESC) VALUES ("Type3");
INSERT INTO TEST.COUNTER_TYPE (COUNTER_TYPE_DESC) VALUES ("Type4");
INSERT INTO TEST.COUNTER_TYPE (COUNTER_TYPE_DESC) VALUES ("Type5");
create table TEST.COUNTER_VAR
(
COUNTER_VAR_ID INTEGER NOT NULL auto_increment,
COUNTER_VAR_NUMBER INTEGER NOT NULL,
COUNTER_VAR_TYPE INTEGER NOT NULL,
INDEX COUNTER_TYPE_IDX (COUNTER_VAR_TYPE),
FOREIGN KEY(COUNTER_VAR_TYPE) REFERENCES
TEST.COUNTER_TYPE(COUNTER_TYPE_ID) ON DELETE CASCADE,
PRIMARY KEY (COUNTER_VAR_ID)
)
type=Innodb;
INSERT INTO TEST.COUNTER_VAR(COUNTER_VAR_NUMBER, COUNTER_VAR_TYPE) VALUES (111,
1);
INSERT INTO TEST.COUNTER_VAR(COUNTER_VAR_NUMBER, COUNTER_VAR_TYPE) VALUES (222,
2);
INSERT INTO TEST.COUNTER_VAR(COUNTER_VAR_NUMBER, COUNTER_VAR_TYPE) VALUES (333,
3);
INSERT INTO TEST.COUNTER_VAR(COUNTER_VAR_NUMBER, COUNTER_VAR_TYPE) VALUES (444,
4);
INSERT INTO TEST.COUNTER_VAR(COUNTER_VAR_NUMBER, COUNTER_VAR_TYPE) VALUES (555,
5);
The main program simply retrieves an instance of CounterVar in the DbLocked
mode and then tries to set a new value of CounterType (which is retrieved in
the DbLocked mode) into it and commit the transaction:
jdo = new JDO("TEST");
jdo.setConfiguration("/root/test/db.xml");
db = jdo.getDatabase();
db.begin();
CounterVar cv = retrieve(1, db);
CounterType ct = retrieveType(3, db);
cv.setType(ct);
db.commit();
db.close();
Both the retrieves are being done in the DbLocked mode.
The exception listed below is seen when doing the commit.
Hope this helps. Please let me know if you need any more information.
Regards, Vishal.
-----Original Message-----
From: Werner Guttmann [mailto:[EMAIL PROTECTED]
Sent: Monday, September 05, 2005 8:45 PM
To: [email protected]
Subject: AW: [castor-dev] Using access="read-only" in the mapping file
Vishal,
please no attachments to a mailing list like this. Just include the relevant
code fragments (actual code, mapping file, etc.) within the body of an email
when making your inquiry.
Regards
Werner
-----Ursprüngliche Nachricht-----
Von: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
Gesendet: Montag, 05. September 2005 16:15
An: [email protected]
Betreff: [castor-dev] Using access="read-only" in the mapping file
Hi,
I have an object that is related to another object which loads data from
a table whose contents are static. For these relations, I have defined
the static data classes as 'access="read-only"' in my mapping file - to
avoid any problems with locking the rows with static data in the DB.
Now, in my main class, I want to change the reference to the static
object at runtime but I am getting the following exception:
[test]# java TestReadOnly
GENERAL EXCEPTION - OUTSIDE BLOCK!!!
org.exolab.castor.jdo.PersistenceException: Object, [EMAIL PROTECTED],
links to another object, [EMAIL PROTECTED] that is not
loaded/updated/created in this transaction
at
org.exolab.castor.persist.ClassMolder.preStore(ClassMolder.java:1326)
at
org.exolab.castor.persist.LockEngine.preStore(LockEngine.java:725)
at
org.exolab.castor.persist.TransactionContext.prepare(TransactionContext.
java:1464)
at
org.exolab.castor.jdo.engine.DatabaseImpl.commit(DatabaseImpl.java:518)
at TestReadOnly.main(TestReadOnly.java:28)
[test]#
The test program and other associated files are attached.
Any help about how I can change the referenced object in the main class
would be appreciated.
Regards, Vishal.
Confidentiality Notice
The information contained in this electronic message and any attachments to
this message are intended
for the exclusive use of the addressee(s) and may contain confidential or
privileged information. If
you are not the intended recipient, please notify the sender at Wipro or [EMAIL
PROTECTED] immediately
and destroy all copies of this message and any attachments.
-------------------------------------------------
If you wish to unsubscribe from this list, please
send an empty message to the following address:
[EMAIL PROTECTED]
-------------------------------------------------
Confidentiality Notice
The information contained in this electronic message and any attachments to
this message are intended
for the exclusive use of the addressee(s) and may contain confidential or
privileged information. If
you are not the intended recipient, please notify the sender at Wipro or [EMAIL
PROTECTED] immediately
and destroy all copies of this message and any attachments.
-------------------------------------------------
If you wish to unsubscribe from this list, please
send an empty message to the following address:
[EMAIL PROTECTED]
-------------------------------------------------