RE: Is "Mapping Classes on Multiple Joined Tables" supported?

2004-12-30 Thread Nils Liebelt
Hi Vadim,

Stick to the Repository file I posted earlier! If you don't use the abstract
modifier for the super class it works. 


Regards,

Nils



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



Re: Howto handle inheritance with an abstract classes

2004-12-30 Thread Thomas Dudziak
Nils Liebelt wrote:
Hi,
I am struggling with a simple extend of an abstract class, trying to use
multiple joined tables.
I get following MetadataException: Can't create new base class object for
'za.co.ibn.datasolutions.entities.Contact'
A soon as I remove the abstract modifier everything works.
Here's my Repository:

   class="za.co.ibn.datasolutions.entities.Contact"
   table="Contact"
 

   
   name="contactID"
   column="contactID"
   jdbc-type="INTEGER"
   primarykey="true"
   autoincrement="true"
   >
   
   
   name="address"
   column="address"
   jdbc-type="VARCHAR"
   length="254"
   >
   


   class="za.co.ibn.datasolutions.entities.Individual"
   table="Individual"
 

   
   
   
   
   

It really don't know what else to try. Did everything according to the
advanced technique tutorial. 
 

The problem seems to be that for storing/materializing an instance of 
Individual, a concrete instance of the type referenced by the 
super-reference is needed. But since this class is abstract, no such 
object can be built. While this scenario may sound feasible in Java 
terms (because the fields of Contact are duplicated in Individual), when 
mapped to a reference OJB's behaviour actually makes sense because the 
mapping is a 'normal' reference. Only there is no concrete field to 
implement the reference on the Java side, but rather an anonymous field 
is used by OJB to store the end of the reference (an instance of 
Contact) and the values of this object are then used for the Individual 
instance.
So, I'd say there is currently no way around making Contact a concrete 
class.

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


Re: Is "Mapping Classes on Multiple Joined Tables" supported?

2004-12-30 Thread Thomas Dudziak
Vadim Gritsenko wrote:
Hey All,
[Using OJB_1_0_RELEASE branch from CVS]
As other users here, I'm also struggling with mapping class hierarchy 
on multiple joined tables, and can't figure out what's wrong and 
whether it is working at all or not.

Consider this slightly modified (added relation to the class C) 
example from the OJB manual page [1]:

/**
 * @ojb.class
 * @ojb.extent-class class-ref="B"
 */
public class A {
/** @ojb.field primarykey="true" autoincrement="ojb" */
Integer id;
/** @ojb.field */
Integer cId;
/** @ojb.reference foreignkey="cId" */
C c;
}
/**
 * @ojb.class include-inherited="false"
 * @ojb.reference class-ref="A" foreignkey="aId"
 * auto-retrieve="true" auto-update="object" auto-delete="object"
 */
public class B extends A
{
/** @ojb.field primarykey="true" autoincrement="ojb" */
Integer id;
/** @ojb.field */
Integer aId;
/** @ojb.field length="254" */
String value;
}
/**
 * @ojb.class
 */
public class C {
/** @ojb.field primarykey="true" autoincrement="ojb" */
Integer id;
/** @ojb.field length="30" */
String name;
}
Ok, once we have that, problems start. First problem is that xdoclet 
does not like include-inherited="false", and when 
include-inherited="true", it generates all inherited attributes into 
repository.xml - but we don't want them there! After some patching of 
xdoclet [2], we can get desired result:
Mhmm, don't know what version of the XDoclet module you're using but 
with the classes that you posted it works for me out-of-the-box (current 
version that comes with 1.0.1) and generates exactly this repository file:


  
  
  
  

  


  
  
  
  

  


  
  

Assuming that all of the above is correct, I'm getting following 
problems on run time:

1. First problem happens when trying to create instance of B (and 
assuming that there is a record for C) with the code:
B b = new B();
b.cId = 1;
b.value = "dummy";
broker.store(b);
This fails with KeyConstraintViolatedException. Seems it is happening 
because B's ClassDescriptor.getSuperClass() returns null and 
PersistentBrokerImpl.storeToDb does not store base class. So what's 
wrong, and can somebody clarify what's the difference between 
getBaseClass and getSuperClass methods? At least getBaseClass() is 
populated correctly.
I'm no expert on the mapping to multiple tables, but this is actually a 
SQL exception coming from the database (I suspect Hsqldb in your case) 
saying that the foreignkey constraint is violated while inserting a row 
into the A table. This can only mean that the referenced C object is not 
present.
You can turn off the generation of the foreign key constraints via the 
generate-foreignkey attribute of the torqueschema Ant task

2. Second problem happens when trying to load existing instance from 
the DB. Fails with OJBRuntimeException "Incorrect or not found field 
reference name 'cId' in descriptor  for class-descriptor 'B'.
Seems like ObjectReferenceDescriptor does not take into account B's 
super class at all.
Strange, this code works just fine for me:
   B bObj = new B();
   C cObj = new C();
   cObj.name  = "The C instance";
   bObj.value = "The B instance";
   bObj.c = cObj;
   PersistenceBroker broker = 
PersistenceBrokerFactory.defaultPersistenceBroker();

   broker.beginTransaction();
   broker.store(bObj);
   broker.commitTransaction();
   broker.close();
   bObj = null;
   cObj = null;
   Criteria criteria = new Criteria();
   criteria.addEqualTo("value", "The B instance");
   QueryByCriteria query = new QueryByCriteria(B.class, criteria);
   broker = PersistenceBrokerFactory.defaultPersistenceBroker();
   broker.beginTransaction();
   bObj = (B)broker.getObjectByQuery(query);
   broker.abortTransaction();
   System.out.println("Loaded B: '"+bObj.value+"' referencing C: 
'"+bObj.c.name+"'");

It prints (as expected):
Loaded B: 'The B instance' referencing C: 'The C instance'
Tom
-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


Re: Is "Mapping Classes on Multiple Joined Tables" supported?

2004-12-30 Thread Vadim Gritsenko
Thomas Dudziak wrote:
Vadim Gritsenko wrote:
Hey All,
[Using OJB_1_0_RELEASE branch from CVS]
As other users here, I'm also struggling with mapping class hierarchy 
on multiple joined tables, and can't figure out what's wrong and 
whether it is working at all or not.

Consider this slightly modified (added relation to the class C) 
example from the OJB manual page [1]:

/**
 * @ojb.class
 * @ojb.extent-class class-ref="B"
 */
public class A {
/** @ojb.field primarykey="true" autoincrement="ojb" */
Integer id;
/** @ojb.field */
Integer cId;
/** @ojb.reference foreignkey="cId" */
C c;
}
/**
 * @ojb.class include-inherited="false"
 * @ojb.reference class-ref="A" foreignkey="aId"
 * auto-retrieve="true" auto-update="object" auto-delete="object"
 */
public class B extends A
{
/** @ojb.field primarykey="true" autoincrement="ojb" */
Integer id;
/** @ojb.field */
Integer aId;
/** @ojb.field length="254" */
String value;
}
/**
 * @ojb.class
 */
public class C {
/** @ojb.field primarykey="true" autoincrement="ojb" */
Integer id;
/** @ojb.field length="30" */
String name;
/** @ojb.collection element-class-ref="A" foreignkey="cId" */
Collection a;
}
Ok, once we have that, problems start. First problem is that xdoclet 
does not like include-inherited="false", and when 
include-inherited="true", it generates all inherited attributes into 
repository.xml - but we don't want them there! After some patching of 
xdoclet [2], we can get desired result:

Mhmm, don't know what version of the XDoclet module you're using but 
with the classes that you posted it works for me out-of-the-box (current 
version that comes with 1.0.1)
I'm sorry, I forgot to add Collection of A's in C (see above). With this 
collection, xdoclet fails - for both 1.0.1 release and 1.0.x branch (I'm working 
off the branch as mentioned above).


and generates exactly this repository file:

  
  
  
  

  


  
  
  
  

  


  
  




Assuming that all of the above is correct, I'm getting following 
problems on run time:

1. First problem happens when trying to create instance of B (and 
assuming that there is a record for C) with the code:
B b = new B();
b.cId = 1;
b.value = "dummy";
broker.store(b);
This fails with KeyConstraintViolatedException. Seems it is happening 
because B's ClassDescriptor.getSuperClass() returns null and 
PersistentBrokerImpl.storeToDb does not store base class. So what's 
wrong, and can somebody clarify what's the difference between 
getBaseClass and getSuperClass methods? At least getBaseClass() is 
populated correctly.

I'm no expert on the mapping to multiple tables, but this is actually a 
SQL exception coming from the database (I suspect Hsqldb in your case) 
saying that the foreignkey constraint is violated while inserting a row 
into the A table. This can only mean that the referenced C object is not 
present.
Yes, it is not: first, you have to create record in table C, before trying 
inserting record into table A. More on this below...


You can turn off the generation of the foreign key constraints via the 
generate-foreignkey attribute of the torqueschema Ant task
But it's not desirable - fk constraints are a good thing to have.

2. Second problem happens when trying to load existing instance from 
the DB. Fails with OJBRuntimeException "Incorrect or not found field 
reference name 'cId' in descriptor  for class-descriptor 'B'.
Seems like ObjectReferenceDescriptor does not take into account B's 
super class at all.

Strange, this code works just fine for me:
   B bObj = new B();
   C cObj = new C();
   cObj.name  = "The C instance";
   bObj.value = "The B instance";
   bObj.c = cObj;
   PersistenceBroker broker = 
PersistenceBrokerFactory.defaultPersistenceBroker();

   broker.beginTransaction();
   broker.store(bObj);
   broker.commitTransaction();
   broker.close();
   bObj = null;
   cObj = null;
   Criteria criteria = new Criteria();
   criteria.addEqualTo("value", "The B instance");
   QueryByCriteria query = new QueryByCriteria(B.class, criteria);
   broker = PersistenceBrokerFactory.defaultPersistenceBroker();
   broker.beginTransaction();
   bObj = (B)broker.getObjectByQuery(query);
   broker.abortTransaction();
   System.out.println("Loaded B: '"+bObj.value+"' referencing C: 
'"+bObj.c.name+"'");
Well, it's getting more strange still... I ran your code (without modifying C 
class) and got (starting with first insert):

[org.apache.ojb.broker.accesslayer.sql.SqlGeneratorDefaultImpl] DEBUG: 
SQL:INSERT INTO A (id,cId) VALUES (?,?)
[org.apache.ojb.broker.accesslayer.JdbcAccessImpl] DEBUG: executeInsert: 
[EMAIL PROTECTED]
Exception in thread "main" org.apache.ojb.broker.KeyConstraintViolatedException: 
SQL failure while insert object data fo
r class A, PK of the given object is [ id=42], object was [EMAIL PROTECTED]

Re: Is "Mapping Classes on Multiple Joined Tables" supported?

2004-12-30 Thread Vadim Gritsenko
Nils Liebelt wrote:
Hi Vadim,
Stick to the Repository file I posted earlier! If you don't use the abstract
modifier for the super class it works. 
I don't have abstract classes anywhere - my case is a bit different. It's about 
mapping classes A and B, where B extends A, to two tables, and class C has 
collection of A.

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


RE: Isolation level for Persistence broker queries

2004-12-30 Thread Vesely, Max [IT]
Is there a particular reason I don't get my questions answered? Just to know it 
will save me some time in the future.

Thanks.



 -Original Message-
From:   Vesely, Max [IT]  
Sent:   Wednesday, December 29, 2004 5:48 PM
To: ojb-user@db.apache.org
Subject:Isolation level for Persistence broker queries

Hello,

Is there any way to specify isolation level for OJB query executed using 
Persistence Broker API? I can see that there's isolation-level attribute 
available for class-descriptor but documentation says it's only used in ODMG 
implementation.

Any help would be greatly appreciated.

Max.

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




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



Re: Isolation level for Persistence broker queries

2004-12-30 Thread Thomas Dudziak
Vesely, Max [IT] wrote:
Is there a particular reason I don't get my questions answered? Just to know it will save me some time in the future.
 

Well, I would say it is because currently there are holidays, so you can 
only reasonably expect answers next week the earliest, I'd say. And the 
people that every once in a while check their mail (like myself) are 
likely not able to answer your question. I for one don't know much about 
the isolation level stuff so I can't help you there.

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


RE: Isolation level for Persistence broker queries

2004-12-30 Thread Vesely, Max [IT]
Thanks. I'll wait for the next week then.

Max.

 -Original Message-
From:   Thomas Dudziak [mailto:[EMAIL PROTECTED] 
Sent:   Thursday, December 30, 2004 7:04 PM
To: OJB Users List
Subject:Re: Isolation level for Persistence broker queries

Vesely, Max [IT] wrote:

>Is there a particular reason I don't get my questions answered? Just to know 
>it will save me some time in the future.
>  
>
Well, I would say it is because currently there are holidays, so you can 
only reasonably expect answers next week the earliest, I'd say. And the 
people that every once in a while check their mail (like myself) are 
likely not able to answer your question. I for one don't know much about 
the isolation level stuff so I can't help you there.

Tom


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




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