문제

I'm updating my code to JPA and I get a error when used the discriminator

@Entity
@DiscriminatorValue("3")
public class WidgetContainer extends Square {
   ...
}

Square.java

@Entity
@Table(name = "square")
@DiscriminatorColumn(name = "squareType", discriminatorType = DiscriminatorType.INTEGER)
@DiscriminatorValue("0")
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
public class Square implements Indexable, Serializable{
   ...
}

I get this error

org.hibernate.WrongClassException: Object with id: 1 was not of the specified subclass: sym.domain.Square (Discriminator: 3)
도움이 되었습니까?

해결책 2

Stupid things happens... I miss add this subclass to the hibernate configuration

<bean id="sessionFactory"
        name="sessionFactoriBla"
        class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
        <property name="annotatedClasses">
            <list>
                                .......
                <value>com.domain.WidgetContainer</value>
                                ......
            </list>
        </property>
...

sorry

다른 팁

I've had a similar issue which was solved by adding this annotation:

@DiscriminatorOptions(force=true)

to the root of the inheritance structure (Square in your case). I don't know if there is a pure JPA way to achieve this.

Java API for DiscriminatorOptions

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top