From Topic 122 ...
I have a very simple object that I have annotated and am building a query with. I am getting an exception that looks like a bug as Postgres needs the AS keyword when aliasing a column. Am I missing some configuration setting?
The code is I use is:
EbeanServer server = Ebean.getServer(null);Query trackQuery = server.createQuery(Track.class);iterator = trackQuery.findList().iterator();
And the exception is:
javax.persistence.PersistenceException: Query threw SQLException:ERROR: syntax error at or near "c0" Query was:select t.id c0, t.name c1, t.gid c2, t.length c3, t.artist c4from track t
I have fixed this by defaulting to use the "AS" keyword for column alias' for all databases (not just Postgres).
As the note: the reason why we need column alias is for the case where concatinated keys are used (and we end up with the same columns references twice in the query). There may be a better long term solution.
I have changed the solution.
Ebean will now only use column alias' for column of imported concatinated keys - otherwise it does not use column alias'.
The reason I have done this is I find it much easier to take the sql and run it externally with the real column names.
If you need to have column alias on ALL columns you can do this by setting alwaysUseColumnAlias=true in ebean.properties:
#### Use column alias on all columns ##ebean.alwaysUseColumnAlias=true
#### change the column alias prefix used###ebean.columnAliasPrefix=as column_