You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@openjpa.apache.org by "Nick Johnson (JIRA)" <ji...@apache.org> on 2007/03/05 05:11:50 UTC

[jira] Created: (OPENJPA-162) @OrderBy on @OneToMany does not allow ordering by @Id value

@OrderBy on @OneToMany does not allow ordering by @Id value
-----------------------------------------------------------

                 Key: OPENJPA-162
                 URL: https://issues.apache.org/jira/browse/OPENJPA-162
             Project: OpenJPA
          Issue Type: Bug
          Components: jpa
    Affects Versions: 0.9.6
         Environment: Using PostgreSQL 8.1 as the database
            Reporter: Nick Johnson


Using the following annotation:

   @OneToMany(mappedBy="root", fetch=FetchType.LAZY)
    @OrderBy("objectId ASC")
    private List<Message> messages;

I get the exception "Cannot order "net.spatula.tally_ho.model.MessageRoot.messages" on "objectId", because that field is not in the default fetch group.  You can only order on fields that will be selected when the related object is loaded."

I should certainly hope that the primary key of the related object is going to be selected when the object is loaded:

    @Id
    @Column(name = "object_id")
    private long objectId;


-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Resolved: (OPENJPA-162) @OrderBy on @OneToMany does not allow ordering by @Id value

Posted by "Abe White (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/OPENJPA-162?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Abe White resolved OPENJPA-162.
-------------------------------

       Resolution: Fixed
    Fix Version/s: 0.9.7

Fixed in revision 514847.  Test case TestIdOrderedOneMany added.

> @OrderBy on @OneToMany does not allow ordering by @Id value
> -----------------------------------------------------------
>
>                 Key: OPENJPA-162
>                 URL: https://issues.apache.org/jira/browse/OPENJPA-162
>             Project: OpenJPA
>          Issue Type: Bug
>          Components: jpa
>    Affects Versions: 0.9.6
>         Environment: Using PostgreSQL 8.1 as the database
>            Reporter: Nick Johnson
>             Fix For: 0.9.7
>
>
> Using the following annotation:
>    @OneToMany(mappedBy="root", fetch=FetchType.LAZY)
>     @OrderBy("objectId ASC")
>     private List<Message> messages;
> I get the exception "Cannot order "net.spatula.tally_ho.model.MessageRoot.messages" on "objectId", because that field is not in the default fetch group.  You can only order on fields that will be selected when the related object is loaded."
> I should certainly hope that the primary key of the related object is going to be selected when the object is loaded:
>     @Id
>     @Column(name = "object_id")
>     private long objectId;

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (OPENJPA-162) @OrderBy on @OneToMany does not allow ordering by @Id value

Posted by "Patrick Linskey (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/OPENJPA-162?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12478122 ] 

Patrick Linskey commented on OPENJPA-162:
-----------------------------------------

I believe that the issue is that the field is not in the current fetch configuration; i.e., it's a lazy relationship. The ID field will clearly be part of the instance that is selected , but when you're selecting Messages, not Threads (or whatever it is that contains Messages).

What happens if you just say '@OrderBy' and leave out the string argument? According to 9.1.28 of the spec, if you just specify @OrderBy and nothing else, the ordering will be ascending by the pk of the associated records, which happens to be what you want.

> @OrderBy on @OneToMany does not allow ordering by @Id value
> -----------------------------------------------------------
>
>                 Key: OPENJPA-162
>                 URL: https://issues.apache.org/jira/browse/OPENJPA-162
>             Project: OpenJPA
>          Issue Type: Bug
>          Components: jpa
>    Affects Versions: 0.9.6
>         Environment: Using PostgreSQL 8.1 as the database
>            Reporter: Nick Johnson
>
> Using the following annotation:
>    @OneToMany(mappedBy="root", fetch=FetchType.LAZY)
>     @OrderBy("objectId ASC")
>     private List<Message> messages;
> I get the exception "Cannot order "net.spatula.tally_ho.model.MessageRoot.messages" on "objectId", because that field is not in the default fetch group.  You can only order on fields that will be selected when the related object is loaded."
> I should certainly hope that the primary key of the related object is going to be selected when the object is loaded:
>     @Id
>     @Column(name = "object_id")
>     private long objectId;

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.