Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JPQL queries without WHERE clause or parameters fail #136

Closed
jacek99 opened this issue Nov 1, 2012 · 3 comments
Closed

JPQL queries without WHERE clause or parameters fail #136

jacek99 opened this issue Nov 1, 2012 · 3 comments

Comments

@jacek99
Copy link

jacek99 commented Nov 1, 2012

it seems that any JPQL query without any parameters gets rejected by Kundera Cassandra.

e.g.

DELETE FROM Country

gives us

javax.persistence.PersistenceException: Bad query format: Country
at com.impetus.kundera.query.KunderaQuery.initEntityClass(KunderaQuery.java:349) ~[kundera-cassandra-2.1-jar-with-dependencies.jar:na]
at com.impetus.kundera.query.KunderaQuery.postParsingInit(KunderaQuery.java:334) ~[kundera-cassandra-2.1-jar-with-dependencies.jar:na]
at com.impetus.kundera.query.QueryResolver.getQueryImplementation(QueryResolver.java:75) ~[kundera-cassandra-2.1-jar-with-dependencies.jar:na]
at com.impetus.kundera.persistence.PersistenceDelegator.createQuery(PersistenceDelegator.java:558) ~[kundera-cassandra-2.1-jar-with-dependencies.jar:na]
at com.impetus.kundera.persistence.EntityManagerImpl.createQuery(EntityManagerImpl.java:441) ~[kundera-cassandra-2.1-jar-with-dependencies.jar:na]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.7.0_09]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) ~[na:1.7.0_09]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.7.0_09]
at java.lang.reflect.Method.invoke(Method.java:601) ~[na:1.7.0_09]
at org.springframework.orm.jpa.ExtendedEntityManagerCreator$ExtendedEntityManagerInvocationHandler.invoke(ExtendedEntityManagerCreator.java:365) ~[spring-orm-3.1.2.RELEASE.jar:3.1.2.RELEASE]
at $Proxy29.createQuery(Unknown Source) ~[na:na]

Likewise for "SELECT FROM Country"

If I look at the code in KunderaQuery (lines 334-349) it does some weird splitting on ":" or "? " and if it doesn't find it rejects the query as invalid.

The Country entity in this case is trivial (with some Lombok @DaTa annotations)

@entity
@table(name="countries", schema="SCHEDULING@scheduling_pu")
@DaTa @EqualsAndHashCode(of="countryCode") @tostring(of={"countryCode","name"})
public class Country {
@id @column(name="country_code")
private String countryCode;
@column(name="name")
private String name;
}

@mevivs
Copy link
Collaborator

mevivs commented Nov 2, 2012

"DELETE FROM Country c " should work for you.

@mevivs
Copy link
Collaborator

mevivs commented Nov 2, 2012

It' s minor bug and it should have worked without giving alias as well!

Here is a test case to demonstrate the same:

https://github.com/impetus-opensource/Kundera/blob/trunk/kundera-cassandra/src/test/java/com/impetus/client/crud/PersonCassandraTest.java

Method: onInsertCassandra

Sample:

        // Delete without WHERE clause.

        String deleteQuery = "DELETE from PersonCassandra p";
        q = em.createQuery(deleteQuery);
        Assert.assertEquals(3, q.executeUpdate());

-Vivek

@xamry
Copy link
Contributor

xamry commented Nov 6, 2012

Fixed. All below variations are valid:
select p from Person p
select from Person p
select from Person.

For valid JPA grammar, see:
http://openjpa.apache.org/builds/1.0.4/apache-openjpa-1.0.4/docs/manual/jpa_langref.html#jpa_langref_bnf

In summary:

select_statement ::= select_clause from_clause [where_clause] [groupby_clause] [having_clause] [orderby_clause]
update_statement ::= update_clause [where_clause]
delete_statement ::= delete_clause [where_clause]

from_clause ::= FROM identification_variable_declaration {, {identification_variable_declaration | collection_member_declaration}}*
update_clause ::= UPDATE abstract_schema_name [[ AS ] identification_variable] SET update_item {, update_item}*
delete_clause ::= DELETE FROM abstract_schema_name [[ AS ] identification_variable]

Here identification variable is optional for UPDATE and DELETE queries, while mandatory for SELECT queries.

Closing...
Amresh

@xamry xamry closed this as completed Nov 6, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants