<@U01SP2GJYAU> If I have a postgres view that I ge...
# komapper
d
@Toshihiro Nakamura If I have a postgres view that I generate that doesn't have any id field... is there a way to make an entity for it?
t
You can use
*@KomapperId(*virtual *=*
true)
for the entity.
You can also use
@KomapperProjection
.
Copy code
@KomapperProjection
data class YourView(
  ...
)
Copy code
val y = ProjectionMeta.YourView
val query = QueryDsl.from(y)
d
Even with virtual = true, it still gives me:
Copy code
column t0_.id does not exist
io.r2dbc.postgresql.ExceptionFactory$PostgresqlBadGrammarException: [42703] column t0_.id does not exist
So I guess I'll have to try with a projection... although I didn't know it could be used like that in the querydsl...? If so, that's better...
But now that I think of it... it doesn't really make sense, since a projection by itself wouldn't know which table to query and it seems like an entity requires an id... which I don't have in that view... (well, it's a string... maybe I could use that...?)
t
Even with virtual = true, it still gives me:
That error message is not output by Komapper. Is that error related to the entity definition in Komapper?
a projection by itself wouldn’t know which table to query
Try following code:
Copy code
@KomapperProjection
@KomapperTable("EmployeeView")
data class YourView(
  ...
)
Copy code
val y = ProjectionMeta.YourView
val query = QueryDsl.from(y)
d
That error message is not output by Komapper. Is that error related to the entity definition in Komapper?
That field really doesn't exist on the table... but I thought that a Komapper Entity w/o an id field (which I don't have in this case...) won't work? So I added the field and thought that virtual would make it that Komapper doesn't look for it at all in a query.
t
Do not add fields that do not exist in the View; give
@KomapperId (virtual = true)
to fields that exist in the View and are substantially unique.
👍🏼 1