Skip to content

[BUG] - SaveCommand的modifiedEntity裁剪报错 #982

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

Closed
SamiuZhong opened this issue Apr 6, 2025 · 3 comments
Closed

[BUG] - SaveCommand的modifiedEntity裁剪报错 #982

SamiuZhong opened this issue Apr 6, 2025 · 3 comments
Labels
bug Something isn't working

Comments

@SamiuZhong
Copy link

Jimmer Version

0.9.71

JDK Version

JDK21

Database

MySQL

OS

Windows

Expected behavior

/

Actual behavior

/

Description

调用代码以下代码时

fun saveUser(user: User, fetcher: Fetcher<User>): User =
    sqlClient.entities.save(user, fetcher).modifiedEntity

如果传入的Fetcher所需形状比现有对象形状小直接裁切的情况,会抛出如下错误

java.lang.ClassCastException: class com.samiu.repository.model.UserDraft$$$Impl cannot be cast to class org.babyfish.jimmer.runtime.DraftSpi (com.samiu.repository.model.UserDraft$$$Impl and org.babyfish.jimmer.runtime.DraftSpi are in unnamed module of loader 'app')

Reproduction steps

/

Generated SQL

No response

Relation Model

No response

Screenshots

No response

Logs

No response

@SamiuZhong SamiuZhong added the bug Something isn't working label Apr 6, 2025
@babyfish-ct
Copy link
Owner

查多和查少都有耽于UT覆盖,需要更多的信息以指导重现。例如:保存的形状和要取的形状

@SamiuZhong
Copy link
Author

实体的定义如:

@Entity
interface User : CreatedEntity, UpdatedEntity {
    @Id
    @GeneratedValue(generatorType = TSIDGenerator::class)
    val id: Long
    val nimToken: String
    val token: String
    val onlineTimestamp: Long
}

报错的代码如:

companion object{
    val LOGIN_FETCHER = newFetcher(User::class).by {
        nimToken()
        token()
    }
}

private fun onLogin( user: User): BaseResponse<Any> {
    val newToken = createToken(user.id)
    val updateUser =  User {
        id = user.id
        token = newToken
        onlineTimestamp = System.currentTimeMillis() / 1000
    }
    // todo
    return successResponse(mRepository.saveUser(updateUser, LOGIN_FETCHER))
}

fun saveUser(user: User, fetcher: Fetcher<User>): User =
    sqlClient.entities.save(user, fetcher).modifiedEntity

@babyfish-ct
Copy link
Owner

Try 0.9.72

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants