Hoi guys,
I try to make the description of my problem as short as possible:
In sql I have:
insert into table_A
(
select property_1, property_2, property_3 from table_B where condition
)
This runs perfectly.
property_n are fields of table_A.
Let's say in hql table_A is represented by object_A and table_B by object_B.
object_A has a composite key made out of property_1 and property_2.
When I want to insert my select result into objec_A, I would like to modify property_2.
My first attempt just for the id of object_A by the select query is:
select new object_id_of_A(object_B.property_1, 'myConstantString') from object_B.
This is ok. When I want to complete the list of properties, like:
select new object_id_of_A(object_B.property_1, 'myConstantString'), object_B.property_3 as myProperty3 from object_B
I get an error (I use Hibernate Perspective):
org.hibernate.hql.ast.QuerySyntaxException: unexpected token: , ...
Digging a little bit further, I found in sql-gen.g the following:
selectClause!
: #(SELECT { handleClauseStart( SELECT ); beforeSelectClause(); } (d:DISTINCT)? x:selectExprList ) {
#selectClause = #([SELECT_CLAUSE,"{select clause}"], #d, #x);
}
;
selectExprList {
boolean oldInSelect = inSelect;
inSelect = true;
}
: ( selectExpr | aliasedSelectExpr )+ {
inSelect = oldInSelect;
}
;
aliasedSelectExpr!
: #(AS se:selectExpr i:identifier) {
setAlias(#se,#i);
#aliasedSelectExpr = #se;
}
;
selectExpr
: p:propertyRef { resolveSelectExpression(#p); }
| #(ALL ar2:aliasRef) { resolveSelectExpression(#ar2); #selectExpr = #ar2; }
| #(OBJECT ar3:aliasRef) { resolveSelectExpression(#ar3); #selectExpr = #ar3; }
| con:constructor { processConstructor(#con); }
| functionCall
| count
| collectionFunction // elements() or indices()
| literal
| arithmeticExpr
| query
;
What I retain from here is that I can either use a con:constructor (selectExpr) OR an aliasedSelectExpr, what means that the combination of both, i.e.
select new obj(), property_3 from table
is IMPOSSIBLE. Is it right? If the answer is yes, is there a workaround (with imbricated inserts or flying keywords in a 4-D screen with adjustable time parameter...)?
Thanks in advance.
à+
Fredy
|