{"action":"created","issue":{"url":"https://api.github.com/repos/ebean-orm/avaje-ebeanorm/issues/787","repository_url":"https://api.github.com/repos/ebean-orm/avaje-ebeanorm","labels_url":"https://api.github.com/repos/ebean-orm/avaje-ebeanorm/issues/787/labels{/name}","comments_url":"https://api.github.com/repos/ebean-orm/avaje-ebeanorm/issues/787/comments","events_url":"https://api.github.com/repos/ebean-orm/avaje-ebeanorm/issues/787/events","html_url":"https://github.com/ebean-orm/avaje-ebeanorm/issues/787","id":167623284,"number":787,"title":"a question about 'order by' with keyword 'desc'","user":{"login":"sfwn","id":13919034,"avatar_url":"https://avatars.githubusercontent.com/u/13919034?v=3","gravatar_id":"","url":"https://api.github.com/users/sfwn","html_url":"https://github.com/sfwn","followers_url":"https://api.github.com/users/sfwn/followers","following_url":"https://api.github.com/users/sfwn/following{/other_user}","gists_url":"https://api.github.com/users/sfwn/gists{/gist_id}","starred_url":"https://api.github.com/users/sfwn/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sfwn/subscriptions","organizations_url":"https://api.github.com/users/sfwn/orgs","repos_url":"https://api.github.com/users/sfwn/repos","events_url":"https://api.github.com/users/sfwn/events{/privacy}","received_events_url":"https://api.github.com/users/sfwn/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2016-07-26T14:35:39Z","updated_at":"2016-07-26T22:35:54Z","closed_at":null,"body":"I'm a Chinese and my English is poor. I can't guarantee whether I could describe the question clearly to you. There is something I'm confused.   \r\nMy develop environment is: kotlin + ebean-orm + spring-boot + mysql.  \r\nI have a model written in kotlin, which has a property called \"desc\" means \"describe\". I know that \"desc\" is also a keyword in mysql, so I add a annotation above \"desc\" and you can see below:  \r\nMy model:\r\n```kotlin\r\n@Entity\r\n@Table(name = \"ps_table\")\r\nclass MyModel {\r\n\r\n    companion object {\r\n        val find = object : Find<Long, MyModel>() {}\r\n    }\r\n\r\n    // other properties\r\n\r\n    var taskId: String? = null\r\n\r\n    @Column(name = \"`desc`\")\r\n    var desc: String? = null\r\n\r\n    @CreatedTimestamp\r\n    open var createdAt: Date? = null\r\n\r\n}\r\n```\r\nNow my aid is to get the descend(who's abbr is also \"desc\") ordered data.  \r\nMy service method in below:  \r\n```kotlin\r\nfun xxxMethod_1(): List<AAA> {\r\n    return AlarmRule.find.where().eq(\"taskId\", taskId).orderBy().desc(\"createdAt\").findList()\r\n}\r\n```\r\nWhen I invoked this method, I got an error below:\r\n```\r\nThere was an unexpected error (type=Internal Server Error, status=500).\r\norg.springframework.web.util.NestedServletException: Request processing failed; \r\nnested exception is javax.persistence.PersistenceException: \r\nQuery threw SQLException:You have an error in your SQL syntax; \r\ncheck the manual that corresponds to your MySQL server version \r\nfor the right syntax to use near 't0.`desc`' at line 1 Bind values:\r\n[MACHINE,true] Query was: select t0.task_id c1, t0.`desc` c2, t0.created_at c3 \r\nfrom ps_table t0 where t0.taskId = ? order by t0.created_at t0.`desc`\r\n```\r\nSomething strange. I set only ONE property \"createdAt\" to descend order my data, but in fact ebean-orm ordered according to TWO properties(Is my understanding right?) so error happens.\r\n\r\nI have found a way to solve my problem. My solution code is:\r\n```kotlin\r\n    fun xxxMethod_2(): List<AAA> {\r\n        return OrderBy<AlarmRule>().run {\r\n            query = AlarmRule.find.where().eq(\"targetType\", targetType).isNull(\"targetId\").eq(\"typeDefault\", true).query()\r\n            desc(\"createdAt\")\r\n        }.findList()\r\n    }\r\n```\r\nIn this way, I can get the right data descend ordered by property \"createdAt\".\r\n\r\nAnd, if I still used the \"xxxMethod_1\" but I remove the property \"desc\" in MyModel, I also can get the right result. So I think the reason is in resolving the keyword \"desc\".\r\n\r\nOf course, I don't know if it is a bug in ebean-orm, or there are some mechanisms I don't know yet. Please tell me and teach me more. \r\n\r\nThank you anyway :)"},"comment":{"url":"https://api.github.com/repos/ebean-orm/avaje-ebeanorm/issues/comments/235427325","html_url":"https://github.com/ebean-orm/avaje-ebeanorm/issues/787#issuecomment-235427325","issue_url":"https://api.github.com/repos/ebean-orm/avaje-ebeanorm/issues/787","id":235427325,"user":{"login":"rbygrave","id":208973,"avatar_url":"https://avatars.githubusercontent.com/u/208973?v=3","gravatar_id":"","url":"https://api.github.com/users/rbygrave","html_url":"https://github.com/rbygrave","followers_url":"https://api.github.com/users/rbygrave/followers","following_url":"https://api.github.com/users/rbygrave/following{/other_user}","gists_url":"https://api.github.com/users/rbygrave/gists{/gist_id}","starred_url":"https://api.github.com/users/rbygrave/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rbygrave/subscriptions","organizations_url":"https://api.github.com/users/rbygrave/orgs","repos_url":"https://api.github.com/users/rbygrave/repos","events_url":"https://api.github.com/users/rbygrave/events{/privacy}","received_events_url":"https://api.github.com/users/rbygrave/received_events","type":"User","site_admin":false},"created_at":"2016-07-26T22:35:54Z","updated_at":"2016-07-26T22:35:54Z","body":"As a side remark - your English is very good and you have done an excellent job of describing your issue.\r\n\r\nWell done!!"}}
{"actor":{"display_login":"rbygrave"}}