Comments (3)
After some more experimentation, this query works as well
fun existsByXAndIsReversedFalse(x: X): Boolean
.
So, If I pass in a full object reference (X) instead of a nested property like id (X.Id) then it works.
from spring-data-jpa.
Care to attach a minimal reproducer so that we can diagnose the issue quicker and more precise?
from spring-data-jpa.
TLDR: I will close this issue as its behaving as expected. Sorry, I should have done this to begin with 😞
Here is how I tried to reproduce it.
package com.example.demo
import jakarta.persistence.*
import org.springframework.boot.CommandLineRunner
import org.springframework.boot.autoconfigure.SpringBootApplication
import org.springframework.boot.runApplication
import org.springframework.context.annotation.Bean
import org.springframework.data.jpa.repository.JpaRepository
@SpringBootApplication
class DemoApplication {
@Bean
fun runner(repository: EmployeeRepo): CommandLineRunner {
return CommandLineRunner { args: Array<String?>? ->
repository.existsByDepartmentIdAndIsHandsomeFalse(25)
println("I was expecting the above to crash but its fine")
}
}
}
fun main(args: Array<String>) {
runApplication<DemoApplication>(*args)
}
interface SomeInterface {
val id: Int
}
@Entity
@Table(name = "person")
@Inheritance(strategy = InheritanceType.JOINED)
open class Person: SomeInterface {
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Id
override var id = 0
@Column(name = "handsome")
var isHandsome = false
}
@Entity
@Table(name = "employee")
open class Employee : Person() {
@ManyToOne(fetch = FetchType.LAZY)
var department: Department? = null
}
@Entity
open class Department {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
var id: Long? = null
var name: String? = null
@OneToMany(fetch = FetchType.LAZY, mappedBy = "department")
var employees: MutableList<Employee> = mutableListOf()
}
interface EmployeeRepo : JpaRepository<Employee?, Long?> {
fun existsByDepartmentIdAndIsHandsomeFalse(departmentId: Long?): Boolean
}
This generates the following SQL
Hibernate: select e1_0.id from employee e1_0 join person e1_1 on e1_0.id=e1_1.id where e1_0.department_id=? and not(e1_1.handsome) fetch first ? rows only
This is working as expected but it does not work in my project with the same setup. Does the repository ultimately depend on the JDBC driver to generate the SQL ? We are using an extremely outdated version of mysql. The SQL I get in my project is the follow. It is missing the join to the "base" table and also crashes with a JDBC exception.
select n1_0.id from employee n1_0 where n1_0.department_id=? and not(n1_1.handsome) limit ?
from spring-data-jpa.
Related Issues (20)
- BadJpqlGrammarException when parsing query containing lateral keyword used as property name. HOT 1
- IDE reports unexpected query tokens on `@Query(INSERT …` HOT 3
- Missing `@Transactional` on `SimpleJpaRepository.delete(spec)` HOT 2
- Provide a way to do DISTINCT ON of PostgresSQL HOT 3
- [Bug] StaleObjectStateException when search in EntityListener @PostRemove method HOT 1
- Search Functionality in Docs Does Not Work HOT 1
- Support of CTE with Pageable HOT 1
- [Virtual Threads] Possible Thread Pinning in `PartTreeJpaQuery.QueryPreparer#createQuery()` HOT 2
- Upgrade to Hibernate 6.4.9.Final. HOT 1
- Upgrade to Eclipselink 4.x
- Spring Data JPA 3.3.0 generates incorrect condition for WHERE clause HOT 3
- Release 3.2.8 (2023.1.8)
- Release 3.3.2 (2024.0.2)
- After upgrading from Spring Boot 2.7.5 to 3.2.5, stored procedure calls treat named parameters as positional parameters. HOT 1
- Unable to start properly after packaging with graalvm HOT 5
- Cannot deal TupleBackedMap type HOT 2
- Dto projection does not work as expected with Kotlin data classes HOT 2
- Switch to Broadcom docker proxy
- weird vscode HQL syntax error in Spring Boot HOT 1
- Investigate 'slim' Specification API
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from spring-data-jpa.