Relationship and on-find strategy
lbroudoux Jul 18, 2003 7:15 AMHello,
I'm using JBoss-3.0.4 and I'd like to set a "on-find" read-ahead strategy to my CMR field. I have bought and read the JBossCMP doco and try to reproduce the "gangster-hangout" optimized loading with a 1-Many relationship.
My use-case is the following : I have to retrieve the permissions/roles of a user during loggin. The relationship is between permission and role (getRole() method into PermissionBean).
Without optimized loading the queries are (my user has 5 roles):
[User.findByPrimaryKey] Executing SQL: SELECT s_id, s_password, s_lastname, s_firstname, s_mail, FROM users WHERE s_id=?
[Permission.findByUserId] Executing SQL: SELECT DISTINCT t0_h.s_id, t0_h.s_reference, t0_h.s_user_fk, t0_h.s_role_fk FROM permissions t0_h WHERE t0_h.s_user_fk = ?
[Role] Executing SQL: SELECT s_label, s_description FROM roles WHERE (s_id=?)
[Role] Executing SQL: SELECT s_label, s_description FROM roles WHERE (s_id=?)
[Role] Executing SQL: SELECT s_label, s_description FROM roles WHERE (s_id=?)
[Role] Executing SQL: SELECT s_label, s_description FROM roles WHERE (s_id=?)
[Role] Executing SQL: SELECT s_label, s_description FROM roles WHERE (s_id=?)
From what I've seen in the book, this loading scenario can become :
[User.findByPrimaryKey] Executing SQL: SELECT s_id, s_password, s_lastname, s_firstname, s_mail, FROM users WHERE s_id=?
[Permission.findByUserId] Executing SQL: SELECT DISTINCT t0_h.s_id, t0_h.s_reference, t0_h.s_user_fk, t0_h.s_role_fk FROM permissions t0_h WHERE t0_h.s_user_fk = ?
[Role] Executing SQL: SELECT s_id, s_label, s_description FROM roles WHERE (s_id=?) OR (s_id=?) OR (s_id=?) OR (s_id=?) OR (s_id=?)
when using a "on-find" read-ahead strategy with a page-size >= 5.
I've modifed the jbosscmp-jdbc.xml descriptor of my app that way :
<ejb-relation>
<ejb-relation-name>Role-OneToMany-Permissions-Uni</ejb-relation-name>
<foreign-key-mapping/>
<ejb-relationship-role>
<ejb-relationship-role-name>Permission-refers-Role</ejb-relationship-role-name>
<fk-constraint>true</fk-constraint>
<key-fields/>
</ejb-relationship-role>
<ejb-relationship-role>
<ejb-relationship-role-name>Role-has-Permissions</ejb-relationship-role-name>
<key-fields>
<key-field>
<field-name>id</field-name>
<column-name>s_role_fk</column-name>
</key-field>
</key-fields>
<read-ahead>
on-find
<page-size>8</page-size>
<eager-load-group>base</eager-load-group>
</read-ahead>
</ejb-relationship-role>
</ejb-relation>
where the "base" load-group contains all the attributes of Role.
Am I missing or misunderstanding something ?
Thanks a lot for your help.
Regards,
--
Laurent