Reputation: 595
With the reactive version of panache I am unable to select a specific column from table using the project
@Entity
class Test: PanacheEntity(){
@Column(name="amount")
var amount: Double = 0.0
@Column(name="name")
lateinit var name: String
}
@ApplicationScoped
class TestRepository: PanacheRepository<Test> {
fun getSum(name: String) =
find("select sum(l.amount) as amount from Test l where l.name = :name",Paramater().with("name", name)
.project(Result::class)
.singleResult()
}
data class Result(val amount: Double)
For sum reason this is generating an incorrect SQL statement i.e.
SELECT new org.package.Result(amount) select sum(l.amount) as amount from org.package.Test l where l.name = $1
It never uses the projection. Is there another way to get the single value from the SQL which is not the entity being used? any workaround for this?
Upvotes: 0
Views: 1614
Reputation: 8236
UPDATE: The issue has been fixed and included in Quarkus 2.12.CR1
As a workaround, you can remove the .project(Result.class)
and run the following query:
select new org.package.Result(sum(l.amount) as amount) from Test l where l.name = :name
The method will look like this:
@ApplicationScoped
class TestRepository: PanacheRepository<Test> {
fun getSum(name: String) =
find("select new org.package.Result(sum(l.amount) as amount) from Test l where l.name = :name",Paramater().with("name", name)
.singleResult()
}
Upvotes: 0