Using JPA2, I can save entities now in JBoss, and also fetch them uniquely by id. However, if I try to fetch it by getting back all instances (e.g. findAll, I get the following error:
org.jboss.arquillian.spi.ArquillianProxyException: com.objectdb.o._PersistenceException : Unexpected query token 'FROM' (SELECT is expected) [Proxied because : Could not find suitable constructor] at com.objectdb.o._PersistenceException.b(_PersistenceException.java:45) at com.objectdb.o.JPE.g(JPE.java:140) at com.objectdb.o.ERR.f(ERR.java:59) at com.objectdb.o.OBC.onObjectDBError(OBC.java:1398)
Code:
public <T extends BaseEntity> List<T> findAll(Class<T> aClass) { CriteriaBuilder qb = entityManager.getCriteriaBuilder(); CriteriaQuery<T> c = qb.createQuery(aClass); c.from(aClass); return entityManager.createQuery(c).getResultList(); }
Entities:
@Entity() @Table(name = "test_entity") public class BaseEntityTest extends BaseEntity{ /** * */ private static final long serialVersionUID = 613965399994067819L; public BaseEntityTest() { super(); } @Column(length = 16) private String testColumn; public String getTestColumn() { return testColumn; } public void setTestColumn(String testColumn) { this.testColumn = testColumn; } } @MappedSuperclass public abstract class BaseEntity implements Serializable{ private static final long serialVersionUID = -7979088681300801112L; /** * Primary key for entity */ @Id // @GeneratedValue(strategy = GenerationType.TABLE, generator = "sequences") // @TableGenerator(name = "sequences", initialValue = 1, allocationSize = 50) // @GeneratedValue(strategy = GenerationType.SEQUENCE) @GeneratedValue private Long id; /** * Version of object, supporting optimistic lock */ @Column (name = "opt_lock") @Version() private Long optimisticLock; /** * Flag to disable entity */ @Column private boolean deleted = false; /** * Audit */ @Embedded private Audit audit; public Long getId() { return id; } public Long getOptimisticLock() { return optimisticLock; } }
The same code, against a PostgreSQL jta datasource works fine however. Is there anything glaringly wrong with my code I'm failing to see? Or is Criteria a W.I.P?
Cheers