Question

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)
Was it helpful?

Solution 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

OTHER TIPS

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top