How to deal with native queries and dtos in kotlin...
# spring
h
How to deal with native queries and dtos in kotlin?
đź‘€ 1
e
I wanted to know whats the point with this question
a
Could you please explain, what is a “native query”?
h
From baeldung: There are three basic types of JPA Queries: Query, written in Java Persistence Query Language (JPQL) syntax NativeQuery, written in plain SQL syntax Criteria API Query, constructed programmatically via different methods
v
Are you using Spring Data JPA? You would write them exactly as you would in Java, but you could make use of multiline strings.
Copy code
@Query(
    value = """select * from something where name = :name""",
    nativeQuery = true
)
fun findSomethingByName(name: String): Something?
a
OK, then you’re talking about JPA. Native query or not, it doesn’t matter. Which query you would use, you still will use entities. For entities, please use usual kotlin classes, not the data classes. You might read something about JPA with data classes at Baeldung’s website and take it for granted. Kotlin data classes are not designed to be used with JPA If you want to learn more about the subject, I suggest this webinar recording:

https://www.youtube.com/watch?v=a_6V8xwiv04â–ľ

152 Views