title: Polymorphic query in spring data
body: <p>I have one base abstract class.</p>
  
  <pre><code>@Entity
  @Table(name = "P_FLD")
  @Inheritance(strategy = InheritanceType.JOINED)
  @DiscriminatorColumn(name = "FLD_DISCRIMINATOR", columnDefinition = "CHAR(3)")
  abstract public class AbstractPassbookField
  </code></pre>
  
  <p>and some classes that extends it. For example:</p>
  
  <pre><code>@Entity
  @DiscriminatorValue("F")
  @Table(name = "P_FLD_F")
  public class PassbookFileField extends AbstractPassbookField
  </code></pre>
  
  <p>and i create repository for base entity </p>
  
  <pre><code>public interface PassbookRepository extends CrudRepository&lt;AbstractPassbookField, Long&gt;
  </code></pre>
  
  <p>I'm running next test</p>
  
  <pre><code>@RunWith(SpringJUnit4ClassRunner.class)
  @ContextConfiguration("classpath:test-config.xml")
  public class PassbookFieldRepositoryTest {
  
      @Autowired
      PassbookRepository passbookRepository;
  
      @PersistenceContext
      private EntityManager em;
  
      @Test
      public void testSave() {
          PassbookFileField passbookFileField = new PassbookFileField();
          passbookFileField.setFilename("text.test");
          passbookFileField.setTemplate(true);
          passbookFileField.setReadonly(true);
          passbookFileField.setImageType(ImageType.I);
          passbookFileField.setResoltuionType(ImageResolutionType.N);
  
          passbookFileField = passbookRepository.save(passbookFileField);
  
          passbookRepository.findAll();
      }
  }
  </code></pre>
  
  <p>passbookRepository.save(passbookFileField) - works well, but
  passbookRepository.findAll() gives me an exception</p>
  
  <pre><code>org.springframework.orm.hibernate3.HibernateObjectRetrievalFailureException: Object [id=1] was not of the specified subclass [ru.teamlabs.moneybox.commons.model.passbook.field.AbstractPassbookField] : Discriminator: F ; nested exception is org.hibernate.WrongClassException: Object [id=1] was not of the specified subclass [ru.teamlabs.moneybox.commons.model.passbook.field.AbstractPassbookField] : Discriminator: F 
  </code></pre>
  
  <p>Quering through entityManager gives me the same error. What I'm doing wrong?</p>