Giter Site home page Giter Site logo

Comments (3)

nanafan93 avatar nanafan93 commented on August 26, 2024

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.

mp911de avatar mp911de commented on August 26, 2024

Care to attach a minimal reproducer so that we can diagnose the issue quicker and more precise?

from spring-data-jpa.

nanafan93 avatar nanafan93 commented on August 26, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.