gpt4 book ai didi

Java EE SqlResultSetMapping 语法

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:20:38 26 4
gpt4 key购买 nike

我有以下 Java 6 代码:

    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 )
}
)

我收到关于最后一个右括号的语法错误。 Eclipse 给出:“插入 EnumBody 以完成 block 语句”和“插入枚举标识符以完成 EnumHeaderName”。来自 javac 的类似语法错误。

我做错了什么?

最佳答案

Hibernate 注释文档 ( http://www.hibernate.org/hib_docs/annotations/reference/en/html_single/ ) 建议这应该是类级别的注释,而不是在您的代码中内联。事实上,当我将该代码粘贴到我的 IDE 中并四处移动时,当注释是内联时会出现编译错误,但当我将它放在类声明上方时就会消失:

@SqlResultSetMapping( name="TripResults",
entities={
@EntityResult( entityClass=TripEntity.class ),
@EntityResult( entityClass=CommercialTripEntity.class )
}
)
public class Foo {
public void bogus() {
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 );
}
}

...显然我没有证据表明上面的代码确实有效。我只是验证了它不会导致编译错误。

关于Java EE SqlResultSetMapping 语法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66528/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com