Hi all,
I have the following entity model:
at first an abstract category entity:
@Entity()
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
@MappedSuperclass()
public abstract class AbstractCategory implements Serializable {
... some common attributes ...
@ManyToOne(cascade = { CascadeType.ALL })
@JoinColumns({ @JoinColumn(name = "FK_PARENT_CATEGORY", nullable = true) })
private AbstractCategory parent = null;
}
now, a concrete entity which extends the abstract category class:
@Entity()
@Table(name = "CONCRETECATEGORY")
public class ConcreteCategory extends AbstractCategory {
... some specific attributes...
}
Next, I've a method which uses ReadAllQuery:
public ConcreteCategory findByExample(ConcreteCategory example) {
ReadAllQuery query = new ReadAllQuery(ConcreteCategory.class);
query.setExampleObject(example);
QueryByExamplePolicy policy = new QueryByExamplePolicy();
policy.addSpecialOperation(String.class, "containsSubstring");
policy.setAttributesToAlwaysInclude(getAlwaysIncludeAttributes());
policy.setShouldUseEqualityForNulls(true);
query.setQueryByExamplePolicy(policy);
List<ConcreteCategory > resultList = JpaHelper.createQuery(query, getEntityManager()).getResultList();
}
If I execute this method I get the following exception:
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table 'myschema.abstractcategory' doesn't exist
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:408)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:409)
at com.mysql.jdbc.Util.getInstance(Util.java:384)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1052)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4232)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4164)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2615)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2776)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2838)
at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:2082)
at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:2212)
at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.executeSelect(DatabaseAccessor.java:1007)
at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.basicExecuteCall(DatabaseAccessor.java:642)
The abstractcategory doesn't have a corresponding database table (because of @MappedSuperclass), therefore it couldn't be found. But how do I write this query the right way?
Thanks in advance for your answers.
Ralf.