dave08
03/12/2023, 12:59 PMToshihiro Nakamura
03/12/2023, 1:47 PMdave08
03/12/2023, 2:06 PMToshihiro Nakamura
03/12/2023, 2:10 PMYou mean making another entity class for the same table?Yes. Alternatively, you could treat the data type of that field as a Blob or Clob.
dave08
03/12/2023, 2:15 PM@KomapperLazy
or @KomapperColumn(lazy = true)
, then it wouldn't be included in the select when loading the whole object, and it would have to be nullable to indicate it wasn't loaded, then only if specified specifically in the field list in select would it actually be loaded... it would allow to use that field in a type-safe way in where's inserts etc... w/o having to load it...Toshihiro Nakamura
03/12/2023, 2:28 PMdave08
03/12/2023, 2:29 PM@KomapperIgnore
but the difference is that it's a real field that is generated in schema generation and can be used in queries...excludeFields
in the querydsl, but it would be a bit less convenient.val MyEntity.address by lazyField("address")
Toshihiro Nakamura
03/12/2023, 2:50 PMexcludeFields in the querydsl,This idea is OK. But wouldn’t having two entity classes for one table be simpler?
dave08
03/12/2023, 2:52 PMvirtualField
or just by field
and the fact that it's a val and just an extension property already indicates it can't be retrievedToshihiro Nakamura
03/12/2023, 3:13 PMdave08
03/12/2023, 3:14 PMMeta
object, not the actual entity... (I got confused at first)... and the same way you'd use a regular Meta definition...@KomapperIgnore
and for schema generation...Toshihiro Nakamura
03/12/2023, 3:28 PMdave08
03/12/2023, 3:30 PM@KomapperEntity
data class Person(
...
) {
@KomapperVirtual
val address: String
}
// would create that field in the db, but not retrieve it by default
@KomapperEntity
data class Person(
...
@KomapperVirtual
val address: String?
) {
constructor(..., /* w/o address */) : this(..., adresss = null)
}
// would create that field in the db and allow using all fields (including address) or just the fields in one of the alternate constructors... then the user would contiously decide what to do to initialize optional fields.
// maybe a constructor could be annotated to help komapper resolve the right one in the query dsl...
val person = QueryDSL.useConstructor(...)...
@KomapperColumn
since it would be distinguished by the fact that it's not in the constructor...Toshihiro Nakamura
03/13/2023, 11:47 AMdave08
03/13/2023, 12:33 PMselect(...)
and get it as a value like this: https://www.komapper.org/docs/reference/query/querydsl/select/#select but it won't be in an instantiated entity object.Toshihiro Nakamura
03/13/2023, 2:54 PM@KomapperEntity
data class Person(
@KomapperId
val id: Int,
@KomapperColumn(autoSelect = false)
val address: String? = null
)
What do you think about the idea of adding an autoSelect
property to @KomapperColumn
? If this property is set to false
, Komapper will check that the default value is specified for the annotated parameter at compile time.dave08
03/13/2023, 3:34 PMToshihiro Nakamura
03/15/2023, 3:49 AM@KomapperEntity
data class Person(
@KomapperId
val id: Int,
val name: String,
val age: Int,
)
@KomapperEntity
@KomapperTable("PERSON")
data class PersonAddress(
@KomapperId
val id: Int,
val address: String // holds large data
)
The second class should only have an ID and a large field.dave08
03/15/2023, 9:53 AMToshihiro Nakamura
03/15/2023, 11:28 AMmaybe it would also be ok to have an excludeFields in the querydsl, but it would be a bit less convenient.I see. Then how about achieving it with QueryDsl, as you say? For example,
val p = Meta.person
val query = QueryDsl.from(p).deselect(p.address, "defalt value")
The second argument of the deselect
function is passed to the constructor of the entity.dave08
03/15/2023, 11:30 AMToshihiro Nakamura
03/15/2023, 12:29 PMThen there would be extra boilerplate in every query to explicitly exclude it.You can reuse a query to reduce boilerplate:
// define a query once
val personQuery = QueryDsl.from(p).deselect(p.address, "defalt value")
// reuse the personQuery
val query1 = personQuery.where { p.id eq 1 }
val query2 = personQuery.where { p.age eq 40 }.orderBy(p.id)
You might as well use an extension function:
// define an extension function
fun <ENTITY : Any, ID : Any, META : EntityMetamodel<ENTITY, ID, META>> QueryDsl.fromPerson(): SelectQueryBuilder<ENTITY, ID, META> {
val p = Meta.person
return QueryDsl.from(p).deselect(p.address, "defalt value")
}
// use the extension function
val query = QueryDsl.fromPerson()
dave08
03/15/2023, 12:33 PM