https://kotlinlang.org logo
j

jfburdet

10/01/2019, 3:35 PM
Hi folks. I just found a bug i my exposed DAO code. The following code returned incorrect value (testing against object instance) collection member : val existingVote = this.votes.firstOrNull { vote -> vote.votedBy == voter } This was fixed by testing against id's : val existingVote = this.votes.firstOrNull { vote -> vote.votedBy.id == voter.id } Why can't I trust testing against object instance ? Shouldnt this be referenced somewhere in the documentation ? Why exposed library doesn't provide a comparison overload operator to compare two IntEntity object ? (this was tested with 0.17.4) Edit again : If i make my class inherit of this class below, this fix my problem ... open class MyIntEntity(id: EntityID<Int>) : IntEntity(id) { override fun equals(other: Any?): Boolean { if (other !is IntEntity) return false return other.id == this.id } } I believe this is because separate instance object have been created by two different transactions ... anyway, it should make sense to expect that such object are somehow the same because they have the same id's ? What do you thing ? Did I found a bug ? Where should I report it ? Last edit ( 😉 ) : I made a sample project to show-case the problem : https://gitlab.com/jfburdet/tstexposed/blob/master/test/kotlin/ComparisonTest.kt ... feel free to clone it and have a look
t

tapac

10/02/2019, 9:11 PM
Entities are equal only with the same transaction as an entity state could mutate between transactions and even original entity could absent in new transaction.
j

jfburdet

10/04/2019, 6:48 AM
That makes sense. I'll refactor my code to make proper use of transactions.