How to combine AND and OR in Spring JPA

I have below JPA which selects all conversations from a particular User.

@Query(
        "select message from Message message
   where message.conversation.id=:cid 
   and message.from.login = ?#{principal.preferredUsername} 
   order by message.createdDate asc "
    )
    List<Message> findAllMessagesForConversation(@Param("cid") Long id);

Problem

I am trying to add one more OR condition like below, but JPA is not supporting (, how to add OR ?

@Query(
        "select message from Message message where 
         message.conversation.id=:cid and
         (message.from.login = ?#{principal.preferredUsername} 
          or message.to.login = ?#{principal.preferredUsername})
          order by message.createdDate asc "
       )
    List<Message> findAllMessagesForConversation(@Param("cid") Long id);
How many English words
do you know?
Test your English vocabulary size, and measure
how many words do you know
Online Test
Powered by Examplum