Issue with Jpa and inheritance

42 Views Asked by At

I've tried to implement some sort of inheritance between 2 classes but eclipse-link fails at the end. I've got a Product class:

@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
@Table(name="product")
@DiscriminatorColumn(name = "product_type_desc", discriminatorType = DiscriminatorType.STRING)
public class Product
{
   @Id
   @GeneratedValue(strategy=GenerationType.IDENTITY)
   @Column(name="id")
   private int id;

   @OneToOne
   @JoinColumn(name = "product_model_id")
   private ProductModel productModel;
}

And a ProductModel class:

@Table(name="product_model")
@DiscriminatorValue("product_model")
public class ProductModel extends Product
{
    @OneToOne(mappedBy = "productModel")
    private Product product;
}

I've then created a DataProvider using the Product class and use it in a Grid. Everything is working fine until I want to filter it on a @ManyToOne property.

I get the following errors

Internal Exception: java.sql.SQLSyntaxErrorException: Unknown column 't0.id' in 'order clause'
Error Code: 1054
Call: SELECT t1.id AS a1, t1.product_model_id AS a89 FROM product_model t1 WHERE (t1.disabled = ?) ORDER BY t0.id DESC LIMIT ?, ?

There's 2 error:

  1. Instead of using the product table, it use product_model
  2. There's a t0 alias in the ORDER BY that's nowhere else...

Here's what I think is happening:

  1. Eclipse link correctly build the query using the product table with t0 as alias
  2. when it build the SELECT it somehow thinks it need product_model and not product
  3. it update the FROM and change the alias to t1 (but don't change the ORDER BY)

I've also tried using a ClassExtractor but no change.

Aditional informations:

  1. We are using EclipseLink 2.7.12
  2. We are using JavaX Persistence 2.2.1
  3. We are using the Criteria API
0

There are 0 best solutions below