<p>I have the following Java 6 code:</p>

<pre><code>    Query q = em.createNativeQuery( 
        "select T.* " +
        "from Trip T join Itinerary I on (T.itinerary_id=I.id) " +
        "where I.launchDate between :start and :end " +
        "or ADDDATE(I.launchDate, I.equipmentPullDayOfTrip) between :start and :end",
        "TripResults" );

    q.setParameter( "start", range.getStart(), TemporalType.DATE );
    q.setParameter( "end", range.getEnd(), TemporalType.DATE );

    @SqlResultSetMapping( name="TripResults",
        entities={
            @EntityResult( entityClass=TripEntity.class ),
            @EntityResult( entityClass=CommercialTripEntity.class )
        }
    )
</code></pre>

<p>I receive a syntax error on the last closing right parenthesis. Eclipse gives: "Insert EnumBody to complete block statement" and "Insert enum Identifier to complete EnumHeaderName".  Similar syntax error from javac.</p>

<p>What am I doing wrong?</p>

[{'answer_id': 66697, 'author': 'Jim Kiley', 'author_id': 7178, 'author_profile': 'https://Stackoverflow.com/users/7178', 'pm_score': 2, 'selected': True, 'text': '<p>The Hibernate annotations docs (<a href="http://www.hibernate.org/hib_docs/annotations/reference/en/html_single/" rel="nofollow noreferrer">http://www.hibernate.org/hib_docs/annotations/reference/en/html_single/</a>) suggest that this should be a class-level annotation rather than occurring inline within your code.  And indeed when I paste that code into my IDE and move it around, the compile errors are present when the annotation is inline, but vanish when I put it in above the class declaration:</p>\n\n<pre><code>@SqlResultSetMapping( name="TripResults",\n        entities={\n            @EntityResult( entityClass=TripEntity.class ),\n            @EntityResult( entityClass=CommercialTripEntity.class )\n        }\n    )\npublic class Foo {\n   public void bogus() {\n      Query q = em.createNativeQuery( \n        "select T.* " +\n        "from Trip T join Itinerary I on (T.itinerary_id=I.id) " +\n        "where I.launchDate between :start and :end " +\n        "or ADDDATE(I.launchDate, I.equipmentPullDayOfTrip) between :start and :end",\n        "TripResults" );\n\n      q.setParameter( "start", range.getStart(), TemporalType.DATE );\n      q.setParameter( "end", range.getEnd(), TemporalType.DATE );\n   }\n}\n</code></pre>\n\n<p>...obviously I have no evidence that the above code will actually work.  I have only verified that it doesn\'t cause compile errors.</p>\n'}, {'answer_id': 66825, 'author': 'Glenn Moss', 'author_id': 5726, 'author_profile': 'https://Stackoverflow.com/users/5726', 'pm_score': 0, 'selected': False, 'text': "<p>Your example comes straight out of the API docs which are unfortunately poorly presented.</p>\n\n<p>Your annotation should be placed on some class, probably the one in which you will be creating the query to use the result set mapping. However, it actually doesn't matter where this annotation is placed. Your JPA provider will actually maintain a global list of all these mappings, so no matter where you define it, you will be able to use it anywhere.</p>\n\n<p>This is a shortcoming of the annotation method (as opposed to specifying things in XML.) Many other things in the JPA (i.e. named queries) are defined this same way. It makes it seem like there's some kind of connection between the thing being defined and the class on which it is annotated, when it's not.</p>\n"}]
['https://Stackoverflow.com/questions/66528', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/-1/']