简体   繁体   中英

Object [id=1] was not of the specified subclass

I am adding a movie to the base MovieEntity class and then another title MovieOtherEnity class that inherits from MovieInfoEntity

MovieInfoEntity has a foreign key to MovieEntity . MovieEntity has lists of entities inheriting from the MovieInfoEntity class.

I have a test where after each test the base is cleared of objects.

/**
 * Clean out the db after every test.
 */
@After
public void cleanup() {
    this.contributionRepository.deleteAll();
    this.messageRepository.deleteAll();
    this.movieRepository.deleteAll(); // here he throws an exception
    this.movieInfoRepository.deleteAll();
    this.userRepository.deleteAll();
}

the line marked in the code above is thrown out

org.springframework.orm.ObjectRetrievalFailureException: Object [id=1] was not of the specified subclass [com.jonki.popcorn.core.jpa.entity.movie.MovieBoxOfficeEntity] : loaded object was of wrong class class com.jonki.popcorn.core.jpa.entity.movie.MovieOtherTitleEntity; nested exception is org.hibernate.WrongClassException: Object [id=1] was not of the specified subclass [com.jonki.popcorn.core.jpa.entity.movie.MovieBoxOfficeEntity] : loaded object was of wrong class class com.jonki.popcorn.core.jpa.entity.movie.MovieOtherTitleEntity

I will mention that it tests the method, where I added the Object MovieOtherTitle item to the list of the MovieEntity object.

似乎不同表之间的ID具有相同的值,因此,当hibernate尝试加载具有特定ID的实体时,如果内存中已经存在另一个具有相同ID的实体,则hibernate会抱怨此问题。

Ensure that in the database, you don't have entries (maybe entered manually) that do not have a defined value in the discriminator column or the value in the column is not a DiscriminatorValue of any of your entities. This will only affect retrieval but not saving.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM