jpql

Syntax error parsing a trivial query with JPA

感情迁移 提交于 2019-12-10 12:59:36
问题 I created the entity bean with netbeans wizard and am trying to get data from database. No matter what SQL query do I use,it doesn't work. I tried using named query that was created by wizard: @NamedQuery(name = "Usr.findAll", query = "SELECT u FROM Usr u") It returns: Caused by: Exception [EclipseLink-8025] (Eclipse Persistence Services - 2.0.1.v20100213-r6600): org.eclipse.persistence.exceptions.JPQLException Exception Description: Syntax error parsing the query [Usr.findAll], line 1,

How to get the database time with JPQL?

僤鯓⒐⒋嵵緔 提交于 2019-12-10 12:36:42
问题 with native SQL I get the database time with a statement like: SELECT CURRENT_TIMESTAMP with JPQL I get the same result with: SELECT CURRENT_TIMESTAMP FROM Customer c WHERE c.id=1 Is there a way to get rid of the last two lines? thanks, 回答1: According to the JSR 220: Enterprise JavaBeans 3.0 specifications: 4.6.16 Functional Expressions The Java Persistence query language includes the following built-in functions, which may be used in the WHERE or HAVING clause of a query . If the value of

Confusing about JPQL

回眸只為那壹抹淺笑 提交于 2019-12-10 12:19:15
问题 I want to JPQL likes following example: Let Hotel object has two objects of Customer and Organization. If Customer is not null, organization will be null. And if the Customer is null , organization will not be null. So I JPQL likes this; Select h.customer.name.firstName, h.organization.name from Hotel h i want to assign one of these two result only to one variable because one is always null. Thanks and Sorry for my english. 回答1: Probably, you are looking for COALESCE() function. Try the

JPQL Update Statement with Join

五迷三道 提交于 2019-12-10 12:14:12
问题 I've never used JPQL before, and I need to use it to batch update the values in a specific column. The column exists in the table, but the entity class was set up without a variable for it. I can't use the exact data, but the setup would be something like this to give you an idea: Database Columns Books: book_id book_title author_id Authors: author_id first_name last_name JPA Entity Classes Books: private Integer bookId; private String bookTitle; private EAuthor author; Authors: private

How do I reuse a parameter witha Spring-Data-JPA Repository?

狂风中的少年 提交于 2019-12-10 11:28:39
问题 In looking at the Query Creation for the Spring Data JPA Repositories, I'm wondering how I would reuse a parameter. For example, how would I name the method if I wanted to do something like: @Query("select c from #{#entityName} c where c.lower <= ?1 and c.upper >= ?1") E findByConversionFor(Double amount); Can that query be converted to a SpEL method name (to be used by the query builder)? It seems like a kludge to require the same value to be passed twice: E

Blank FROM clause in JPQL?

折月煮酒 提交于 2019-12-10 10:24:28
问题 I'm using a JPQL select to access a Oracle DB function: select FUNCTION('function_name', 'foo', 1234) from com_mycompany_bar obj This works as expected and the function is indeed called. The thing is I actually don't need the FROM clause and would rather have it empty instead of having to access an entity just to conform to the syntax. What is the best option I have here? 回答1: I see several possible answers: Within standard JPA there are two options, both involving Oracle DUAL "table" Map

JPA: Query an embeddable List inside an entity

假如想象 提交于 2019-12-10 10:08:08
问题 I am trying to "extract" Embeddable classes based on some criterias from a list in an Entity. Either with the help of JPQL or Criteria API. I am not a pro at this, so please help me out. Been googling for 4 hours solid for an answer without any results. These are the classes: @Entity public class PostOffice { @Id private Long id; @ElementCollection(fetch=FetchType.LAZY) @CollectionTable(joinColumns=@JoinColumn(name = "CARRIERID")) private List<PostalCarrier> carriers; } @Embeddable public

JPA: java.lang.StackOverflowError on adding toString method in entity classes

狂风中的少年 提交于 2019-12-09 18:01:34
问题 Everything worked fine until I added toSting() in my entity classes. After which I start getting the following error in runtime: Exception in thread "main" java.lang.StackOverflowError at java.lang.AbstractStringBuilder.append(Unknown Source) at java.lang.StringBuilder.append(Unknown Source) at java.lang.StringBuilder.<init>(Unknown Source) at entity.Guide.toString(Guide.java:51) at java.lang.String.valueOf(Unknown Source) at java.lang.StringBuilder.append(Unknown Source) at entity.Student

How to do a timestamp comparison with JPA query?

﹥>﹥吖頭↗ 提交于 2019-12-09 16:11:43
问题 We need to make sure only results within the last 30 days are returned for a JPQL query. An example follows: Date now = new Date(); Timestamp thirtyDaysAgo = new Timestamp(now.getTime() - 86400000*30); Query query = em.createQuery( "SELECT msg FROM Message msg "+ "WHERE msg.targetTime < CURRENT_TIMESTAMP AND msg.targetTime > {ts, '"+thirtyDaysAgo+"'}"); List result = query.getResultList(); Here is the error we receive: <openjpa-1.2.3-SNAPSHOT-r422266:907835 nonfatal user error> org.apache

JPQL Query using max on a date field

萝らか妹 提交于 2019-12-09 15:41:44
问题 I need to query to find a record with the most recent date from a group of records. I've tried a bunch of stuff, with the most recent being something like this: select msg, msg.createdDate from ImportedMessage msg where msg.siteId = ?1 and msg.createdDate = max(msg.createdDate) group by msg.createdDate Unfortunately, everything I've tried has yielded some sort of error. The error I seem to get most is: Caused by: java.sql.SQLException: Not in aggregate function or group by clause: org.hsqldb