Hello,
1) I'm trying JDO and I receiving errors. Exactly, sometimes (50%) when I'm saving
objects are objects in collection saved twice.
I'm using ojb 0.99 built from source connected to mysql DB.
I have two classes Person and Address. One Person can have 0..n Addresses, so I'have
collection adresy in Person object ( private Vector adresy;). I'have auto-update = true
When I save object Person with PB everything runs OK, I can see one new Person in
table "Person" and new Addresses in table "Address" (if I'm saving two then there are
two rows).
When I use JDO, it saves one Person (it's OK), but at 50% of runs there are more rows
than Addresses to save (Some rows are duplicated, identical).
Log from JDO looks like this (one Person, two Addresses, seems OK):
*********************************
[JDO] DEBUG: OjbStoreManager.flush: com.uvt.Address{303}, P_NEW
[JDO] DEBUG: OjbStoreManager.insert
[JDO] DEBUG: OjbStoreManager.flush: com.uvt.Person{282}, P_NEW
[JDO] DEBUG: OjbStoreManager.insert
[JDO] DEBUG: OjbStoreManager.flush: com.uvt.Address{302}, P_NEW
[JDO] DEBUG: OjbStoreManager.insert
[JDO] DEBUG: OjbStoreManager.flush: end, err=false
[JDO] DEBUG: OjbStoreConnector.commit
*********************************
but then there are identical rows (sometimes only one Address is duplicated, sometimes
both).
My code looks like this:
********************************
public boolean savePerson() {
Person person = null;
Address adresa = null;
Address adresa2 = null;
PersistenceManager manager = null;
PersistenceManagerFactory factory = null;
person = new Person();
person.setJmeno("Thomas");
person.setPrijmeni("Klubal");
adresa2 = new Address();
adresa2.setUlice("Greeen st. 256");
adresa2.setMesto("Prague");
adresa2.setPsc("165 00");
person.addAddress(adresa2);
adresa = new Address();
adresa.setUlice("Red st. 45");
adresa.setMesto("Paris");
adresa.setPsc("895422");
person.addAddress(adresa);
try {
factory = new OjbStorePMF();
manager = factory.getPersistenceManager();
Transaction tx = null;
tx = manager.currentTransaction();
tx.begin();
manager.makePersistent(person);
tx.commit();
System.out.println("\nPerson saved. " + person.toString());
manager.close();
}
catch (PersistenceBrokerException ex) {
System.out.println("Error: " + ex.getMessage());
return false;
}
return true;
}
*************************************************************
this is my repiository_user.xml:
<class-descriptor class="com.uvt.Address" table="Address">
<field-descriptor id="1" name="oid" column="oid" jdbc-type="INTEGER"
primarykey="true" autoincrement="true"></field-descriptor>
<field-descriptor id="2" name="oidPerson" column="oidPerson"
jdbc-type="INTEGER"></field-descriptor>
<field-descriptor id="3" name="ulice" column="ulice"
jdbc-type="VARCHAR"></field-descriptor>
<field-descriptor id="4" name="mesto" column="mesto"
jdbc-type="VARCHAR"></field-descriptor>
<field-descriptor id="5" name="psc" column="psc"
jdbc-type="VARCHAR"></field-descriptor>
</class-descriptor>
<class-descriptor class="com.uvt.Person" table="Person">
<field-descriptor id="1" name="oid" column="oid" jdbc-type="INTEGER"
primarykey="true" autoincrement="true"></field-descriptor>
<field-descriptor id="2" name="jmeno" column="jmeno"
jdbc-type="VARCHAR"></field-descriptor>
<field-descriptor id="3" name="prijmeni" column="prijmeni"
jdbc-type="VARCHAR"></field-descriptor>
<collection-descriptor name="adresy" element-class-ref="com.uvt.Address"
orderby="oid" sort="DESC" auto-retrieve="true" auto-update="true" auto-delete="true">
<inverse-foreignkey field-id-ref="2"></inverse-foreignkey>
</collection-descriptor>
</class-descriptor>
Please dont you know whats wrong?
Tomas Klubal :-)
E-mail: [EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]