Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » Problem with ReadAllQuery and hierarchical data(Exception if executing a query)
Problem with ReadAllQuery and hierarchical data [message #1451399] Thu, 23 October 2014 19:30 Go to next message
Ralf Heydenreich is currently offline Ralf HeydenreichFriend
Messages: 235
Registered: July 2009
Senior Member
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.
Re: Problem with ReadAllQuery and hierarchical data [message #1453837 is a reply to message #1451399] Mon, 27 October 2014 15:23 Go to previous messageGo to next message
Rick Curtis is currently offline Rick CurtisFriend
Messages: 24
Registered: September 2014
Location: Rochester, MN
Junior Member
Try to remove the @Entity annotation from AbstractCategory.
Re: Problem with ReadAllQuery and hierarchical data [message #1453941 is a reply to message #1453837] Mon, 27 October 2014 18:42 Go to previous message
Ralf Heydenreich is currently offline Ralf HeydenreichFriend
Messages: 235
Registered: July 2009
Senior Member
Am 27.10.2014 um 16:23 schrieb Rick Curtis:
> Try to remove the @Entity annotation from AbstractCategory.

Hi Rick,
this leads to the following exception:

Exception Description: [class my.own.model.AbstractCategory] uses a
non-entity [class my.own.model.AbstractCategory] as target entity in the
relationship attribute [field parent].

Meanwhile, I've put all the categories in one single table
(InheritanceType.SINGLE_TABLE) and it works for now. I only thought if
there are more and more categories the table gets to big.

Ralf.
Previous Topic:Schema per Tenant issues
Next Topic:No [ManagedType] was found for the key class.. JPA, H2, EclipseLink, Java Config (no xml)
Goto Forum:
  


Current Time: Fri Apr 19 02:51:31 GMT 2024

Powered by FUDForum. Page generated in 0.01884 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top