Hi All,
I'm not quite certain this is where I should be sending this message but I'm at
a loss as to what the cause of my error is and at the base it seems to be
coming from Derby.
I've encountered a strange issue when using Derby as my data store in
conjunction with JPA 2.0. I'm a novice and really have been trying to follow
examples that I have seen on how this should be configured. That said I'm
receiving the following when doing either a named or criteria query.
Interestingly enough I have been able to store the Product and retrieve it
using the entityManager.getReference(Product.class,
"urn:uuid:223123-123123-123123") but not filtering using the Criteria API. I
also attempted to do a NamedQuery but ended up getting the same issue below.
javax.persistence.PersistenceException:
org.hibernate.exception.GenericJDBCException: could not execute query
at
org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:804)
at org.hibernate.ejb.QueryImpl.getSingleResult(QueryImpl.java:271)
at
org.hibernate.ejb.criteria.CriteriaQueryCompiler$2.getSingleResult(CriteriaQueryCompiler.java:125)
at
gov.nasa.pds.registry.service.MetadataStoreJPA.getProduct(MetadataStoreJPA.java:130)
......
Caused by: ERROR XCL13: The parameter position '3' is out of range. The number
of parameters for this prepared statement is '2'.
at org.apache.derby.iapi.error.StandardException.newException(Unknown Source)
at org.apache.derby.impl.sql.GenericParameterValueSet.checkPosition(Unknown
Source)
at
org.apache.derby.impl.sql.GenericParameterValueSet.getParameterForSet(Unknown
Source)
The following code is the class which uses JPA. As you can probably see I am
using Spring to inject the entityManager.
@Repository(value="metadataStore")
public class MetadataStoreJPA implements MetadataStore {
private EntityManager entityManager;
@PersistenceContext
public void setEntityManager(EntityManager entityManager) {
this.entityManager = entityManager;
}
public EntityManager getEntityManager() {
return entityManager;
}
@Transactional(readOnly = true)
public Product getProduct(String lid, String userVersion) {
CriteriaBuilder cb = entityManager.getCriteriaBuilder();
CriteriaQuery<Product> cq = cb.createQuery(Product.class);
Root<Product> productEntity = cq.from(Product.class);
Path<String> lidAttr = productEntity.get("lid");
Path<String> userVersionAttr = productEntity.get("userVersion");
cq.where(cb.and(cb.equal(lidAttr, lid), cb.equal(userVersionAttr,
userVersion)));
TypedQuery<Product> query = entityManager.createQuery(cq);
Product product = query.getSingleResult();
return product;
}
My entity classes are as follows:
@Entity
public class Product extends RegistryObject {
private static final long serialVersionUID = 4629220512391515679L;
private String contentVersion;
private String mimeType;
@MappedSuperclass
public abstract class RegistryObject extends Identifiable {
private static final long serialVersionUID = 1477919575493686135L;
private String lid;
private String name;
private String objectType;
private ObjectStatus status;
private String description;
private String version;
private String userVersion;
@MappedSuperclass
public abstract class Identifiable implements Serializable {
private static final long serialVersionUID = -1707014666352827997L;
@Id
private String guid;
private String home;
@OneToMany
private Set<Slot> slots;
@Entity
public class Slot implements Serializable {
private static final long serialVersionUID = -7500835856314553723L;
@Id
@GeneratedValue
private long id;
private String name;
@ElementCollection
@CollectionTable(name="SlotValues", joincolum...@joincolumn(name="parent_slot"))
private List<String> values;
Any direction or feedback as to where I should look to resolve this issue would
be greatly appreciated. If more detail is needed such as a mvn dependency:tree,
applicationContext.xml, or persistence.xml please let me know. I was trying to
keep it brief and hoping that it was just something wrong with the annotations
above.
Thanks,
Paul Ramirez