You are viewing a plain text version of this content. The canonical link for it is here.
Posted to ojb-user@db.apache.org by Marcus Young <ma...@redcentre.com> on 2004/07/07 15:29:21 UTC
recursive maps
Hi,
I have two classes 'Role' and 'Group' that extend 'PermissionHolder".
PermissionHolder includes as an attribute a collection of
PermissionHolders. I am able to store a Role or a Group with contained
permission holders successfully. However, I am having difficulties with
retrevial. Exception as follows:
[org.apache.ojb.broker.accesslayer.JdbcAccessImpl] DEBUG: executeQuery:
com.mysql.jdbc.PreparedStatement@15bdc50: SELECT
A0.NAME,A0.DESCRIPTION,A0.ID FROM roles A0 WHERE A0.ID = 1584
[org.apache.ojb.broker.accesslayer.RsIterator] DEBUG:
RsIterator[org.apache.ojb.broker.accesslayer.RsQueryObject[query:
QueryByCriteria from class com.eclipsej.user.RoleTO where [_id = 1584],
class descriptor: com.eclipsej.user.RoleTO]] initialized
[org.apache.ojb.broker.accesslayer.RsIterator] DEBUG: hasNext() -> true
java.lang.NullPointerException
at
org.apache.ojb.broker.metadata.ClassDescriptor.getPkFields(ClassDescriptor.java:1016)
at
org.apache.ojb.broker.core.QueryReferenceBroker.getFKQueryMtoN(QueryReferenceBroker.java:660)
at
org.apache.ojb.broker.core.Que[org.apache.ojb.broker.core.PersistenceBrokerImpl]
DEBUG: PB.close was called:
org.apache.ojb.broker.core.PersistenceBrokerImpl@1a5f739
[org.apache.ojb.broker.cache.InternalCache] WARN: Found 1 abandoned
objects in local cache, check code to force push to real ObjectCache
ryReferenceBroker.getFKQuery(QueryReferenceBroker.java:608)
In this case role (id=1584) has a single group in its collection.
I have also attached a copy of the repository. I'm sure I'm missing
something simple - any help would be appreciated....
<!-- Definitions for com.eclipsej.permissions.PermissionHolder -->
<class-descriptor class="com.eclipsej.permission.PermissionHolder"
table="permission_holders">
<extent-class class-ref="com.eclipsej.user.RoleTO" />
<extent-class class-ref="com.eclipsej.user.GroupTO" />
</class-descriptor>
<!-- Defnitions for com.eclipsej.user.RoleTO -->
<class-descriptor class="com.eclipsej.user.RoleTO" table="roles">
<field-descriptor name="_id" column="ID" jdbc-type="BIGINT"
primarykey="true" autoincrement="true"/>
<field-descriptor name="_name" column="NAME" jdbc-type="VARCHAR"/>
<field-descriptor name="_description" column="DESCRIPTION"
jdbc-type="VARCHAR"/>
<collection-descriptor name="_permissionHolders"
element-class-ref="com.eclipsej.permission.PermissionHolder"
auto-retreive="true"
auto-update="true"
auto-delete="false"
indirection-table="permission_holder_map"
>
<fk-pointing-to-this-class column="permission_holder_host_id"/>
<fk-pointing-to-element-class
column="permission_holder_client_id"/>
</collection-descriptor>
</class-descriptor>
Marcus
---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org
Re: recursive maps
Posted by Thomas Dudziak <to...@first.fhg.de>.
Marcus Young wrote:
> Thanks Tom - the test cases against role and group now function
> correclty. The record id's appear to be unique across the extent set?
Depends on how you get their values. A simple MySQL-style autoincrement
in the database won't work, but if you're letting OJB create the values,
or if you have a database sequence defined for it, then you should be fine.
> Interestingly however, no data is actually written to the
> 'permission_holder' table - this includes the permisison holder id and
> any test attributes that are added to the permission holder class. This
> started me thinking about the possibility of a class-descriptor that
> defines a class that has no direct map to a database table. This
> descriptor would only contain information detailing relationships
> between other class-descriptors. I'm fairly new to this, so I not sure
> if this makes sense?!
Mapping an inheritance hierarchy to multiple tables is a somewhat
involved topic. If you haven't checked already, you should look here for
some details:
http://db.apache.org/ojb/docu/guides/advanced-technique.html#Mapping+Classes+on+Multiple+Joined+Tables
Basically you need references that use the special keyword 'super' to
referer to the base instance.
It would be a lot easier if you were able to map all subclass of
PermissionHolder to the same table, because in this case you'll only
need an additional field 'ojbConcreteClass' that tells OJB which class
to instantiate when reading a row from the table.
Tom
---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org
Re: recursive maps
Posted by Marcus Young <ma...@redcentre.com>.
Thanks Tom - the test cases against role and group now function
correclty. The record id's appear to be unique across the extent set?
Interestingly however, no data is actually written to the
'permission_holder' table - this includes the permisison holder id and
any test attributes that are added to the permission holder class. This
started me thinking about the possibility of a class-descriptor that
defines a class that has no direct map to a database table. This
descriptor would only contain information detailing relationships
between other class-descriptors. I'm fairly new to this, so I not sure
if this makes sense?!
Marcus
Thomas Dudziak wrote:
> Your m:n collection points to PermissionHolder, however this 'class'
> has no declared primary key field. Try adding the primary key field
> descriptor to it. Note that the primary key must be unique across
> RoleTO and GroupTO to make this work. You might also run into problems
> if you map RoleTO and GroupTO to different tables because in this case
> OJB currently has no way to determine which class to instantiate
> (there are plans to add support for a field containing the concrete
> class name to the referee side, e.g. the indirection table in your
> case, but they ain't implemented yet).
>
> Tom
---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org
Re: recursive maps
Posted by Thomas Dudziak <to...@first.fhg.de>.
Marcus Young wrote:
> Hi,
>
> I have two classes 'Role' and 'Group' that extend 'PermissionHolder".
> PermissionHolder includes as an attribute a collection of
> PermissionHolders. I am able to store a Role or a Group with contained
> permission holders successfully. However, I am having difficulties with
> retrevial. Exception as follows:
>
> [org.apache.ojb.broker.accesslayer.JdbcAccessImpl] DEBUG: executeQuery:
> com.mysql.jdbc.PreparedStatement@15bdc50: SELECT
> A0.NAME,A0.DESCRIPTION,A0.ID FROM roles A0 WHERE A0.ID = 1584
> [org.apache.ojb.broker.accesslayer.RsIterator] DEBUG:
> RsIterator[org.apache.ojb.broker.accesslayer.RsQueryObject[query:
> QueryByCriteria from class com.eclipsej.user.RoleTO where [_id = 1584],
> class descriptor: com.eclipsej.user.RoleTO]] initialized
> [org.apache.ojb.broker.accesslayer.RsIterator] DEBUG: hasNext() -> true
> java.lang.NullPointerException
> at
> org.apache.ojb.broker.metadata.ClassDescriptor.getPkFields(ClassDescriptor.java:1016)
>
> at
> org.apache.ojb.broker.core.QueryReferenceBroker.getFKQueryMtoN(QueryReferenceBroker.java:660)
>
> at
> org.apache.ojb.broker.core.Que[org.apache.ojb.broker.core.PersistenceBrokerImpl]
> DEBUG: PB.close was called:
> org.apache.ojb.broker.core.PersistenceBrokerImpl@1a5f739
> [org.apache.ojb.broker.cache.InternalCache] WARN: Found 1 abandoned
> objects in local cache, check code to force push to real ObjectCache
> ryReferenceBroker.getFKQuery(QueryReferenceBroker.java:608)
>
>
> In this case role (id=1584) has a single group in its collection.
> I have also attached a copy of the repository. I'm sure I'm missing
> something simple - any help would be appreciated....
>
>
> <!-- Definitions for com.eclipsej.permissions.PermissionHolder -->
> <class-descriptor class="com.eclipsej.permission.PermissionHolder"
> table="permission_holders"> <extent-class
> class-ref="com.eclipsej.user.RoleTO" />
> <extent-class class-ref="com.eclipsej.user.GroupTO" />
> </class-descriptor>
> <!-- Defnitions for com.eclipsej.user.RoleTO -->
> <class-descriptor class="com.eclipsej.user.RoleTO" table="roles">
> <field-descriptor name="_id" column="ID" jdbc-type="BIGINT"
> primarykey="true" autoincrement="true"/>
> <field-descriptor name="_name" column="NAME" jdbc-type="VARCHAR"/>
> <field-descriptor name="_description" column="DESCRIPTION"
> jdbc-type="VARCHAR"/> <collection-descriptor
> name="_permissionHolders"
> element-class-ref="com.eclipsej.permission.PermissionHolder"
> auto-retreive="true"
> auto-update="true"
> auto-delete="false"
> indirection-table="permission_holder_map"
> >
> <fk-pointing-to-this-class column="permission_holder_host_id"/>
> <fk-pointing-to-element-class
> column="permission_holder_client_id"/>
> </collection-descriptor> </class-descriptor>
Your m:n collection points to PermissionHolder, however this 'class' has
no declared primary key field. Try adding the primary key field
descriptor to it. Note that the primary key must be unique across RoleTO
and GroupTO to make this work. You might also run into problems if you
map RoleTO and GroupTO to different tables because in this case OJB
currently has no way to determine which class to instantiate (there are
plans to add support for a field containing the concrete class name to
the referee side, e.g. the indirection table in your case, but they
ain't implemented yet).
Tom
---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org