-
Notifications
You must be signed in to change notification settings - Fork 198
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Using CriteriaBuilder with embedded IDs #3125
Comments
I did hack out a workaround by implementing a (terrible, ugly) PersistentPropertyPath: package mypackage
import io.micronaut.data.model.Association
import io.micronaut.data.model.PersistentEntity
import io.micronaut.data.model.PersistentProperty
import io.micronaut.data.model.jpa.criteria.PersistentEntityPath
import io.micronaut.data.model.jpa.criteria.PersistentPropertyPath
import io.micronaut.data.model.jpa.criteria.impl.ExpressionVisitor
import jakarta.persistence.criteria.Expression
import jakarta.persistence.criteria.Path
import jakarta.persistence.criteria.Root
import jakarta.persistence.metamodel.Bindable
import jakarta.persistence.metamodel.MapAttribute
import jakarta.persistence.metamodel.PluralAttribute
import jakarta.persistence.metamodel.SingularAttribute
internal class BasicPersistentPropertyPath<T>(
val name: String,
private val alias: String,
private val type: Class<T>,
private val parent: Root<*>
) : PersistentPropertyPath<T> {
override fun getJavaType(): Class<out T> = type
override fun getModel(): Bindable<T> {
TODO("Not yet implemented")
}
override fun getParentPath(): Path<*> = parent
override fun <Y : Any?> get(attributeName: String?): Path<Y> {
TODO("Not yet implemented")
}
override fun type(): Expression<Class<out T>> {
TODO("Not yet implemented")
}
override fun visitExpression(expressionVisitor: ExpressionVisitor?) {
TODO("Not yet implemented")
}
override fun getProperty(): PersistentProperty = object : PersistentProperty {
override fun getName(): String = this@BasicPersistentPropertyPath.name
override fun getPersistedName(): String = this@BasicPersistentPropertyPath.alias
override fun getTypeName(): String {
TODO("Not yet implemented")
}
override fun getOwner(): PersistentEntity {
return (parent as PersistentEntityPath<*>).persistentEntity ?:
throw IllegalStateException("No owner found for property: $name")
}
override fun isAssignable(type: String?): Boolean {
TODO("Not yet implemented")
}
}
override fun getAssociations(): MutableList<Association> = mutableListOf()
override fun <K : Any?, V : Any?, M : MutableMap<K, V>?> get(map: MapAttribute<T, K, V>?): Expression<M> {
TODO("Not yet implemented")
}
override fun <E : Any?, C : MutableCollection<E>?> get(collection: PluralAttribute<T, C, E>?): Expression<C> {
TODO("Not yet implemented")
}
override fun <Y : Any?> get(attribute: SingularAttribute<in T, Y>?): Path<Y> {
TODO("Not yet implemented")
}
} Usage in my case: return criteriaBuilder.and(
criteriaBuilder.equal(
BasicPersistentPropertyPath<String>("familyId", "family_id", String::class.java, root),
id.familyId),
criteriaBuilder.equal(BasicPersistentPropertyPath<String>(
"memberId", "member_id", String::class.java, root),
id.memberId)
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Expected Behavior
I'm trying to write an update criteria that updates a row with a composite key. An abbreviated version of the classes involved:
And I'm trying to write an
UpdateSpecification<MemberProfileDto>
:Actual Behaviour
From logs it looks like the SQL generated is correct, but the arguments bound are not:
The bound values appear to just be
toString
of the MemberProfileId class, not the individual components.I've tried a fair number of things to try working around this, but nothing has been successful so far. Is there a hook into the conversion to string I could use to perform the correct value binding?
I saw a discussion about a similar issue from > 2 years ago, with no answer. I'm figuring this is a bug, or that I've missed something.
Steps To Reproduce
Environment Information
Example Application
No response
Version
4.6.1
The text was updated successfully, but these errors were encountered: