cancel
Showing results for 
Search instead for 
Did you mean: 

ExpressionNodeManager.endOfExpression in EntityManager.createQuery

Former Member
0 Kudos

java.lang.ArrayIndexOutOfBoundsException: -1

at com.sap.engine.services.orpersistence.sqlmapper.common.ExpressionNodeManager.endOfExpression(ExpressionNodeManager.java:2164)

at com.sap.engine.services.orpersistence.sqlmapper.common.EJBLoadStoreBuilder.createBeanLoading(EJBLoadStoreBuilder.java:219)

at com.sap.engine.services.orpersistence.sqlmapper.common.CommonSQLMapper.createEJBSelect(CommonSQLMapper.java:497)

at com.sap.engine.services.orpersistence.sqlmapper.SQLMapperHelper.createQueryDataForFind(SQLMapperHelper.java:57)

at com.sap.engine.services.orpersistence.sqlmapper.SQLMapperHelper.<init>(SQLMapperHelper.java:49)

at com.sap.engine.services.orpersistence.entitymanager.EntityManagerFactoryImpl$MetaDataImpl.<init>(EntityManagerFactoryImpl.java:151)

at com.sap.engine.services.orpersistence.entitymanager.EntityManagerFactoryImpl.getPersistenceUnitData(EntityManagerFactoryImpl.java:124)

at com.sap.engine.services.orpersistence.core.PersistenceContextImpl.<init>(PersistenceContextImpl.java:69)

at com.sap.engine.services.orpersistence.entitymanager.EntityManagerImpl.<init>(EntityManagerImpl.java:71)

at com.sap.engine.services.orpersistence.entitymanager.JtaEntityManagerFactoryImpl.createEntityManagerInternal(JtaEntityManagerFactoryImpl.java:57)

at com.sap.engine.services.orpersistence.entitymanager.JtaEntityManagerFactoryImpl.createEntityManager(JtaEntityManagerFactoryImpl.java:49)

at com.sap.engine.services.orpersistence.container.EMManager.createEntityManager(EMManager.java:202)

at com.sap.engine.services.orpersistence.container.EMManager.getTransactionEntityManager(EMManager.java:77)

at com.sap.engine.services.orpersistence.container.EntityManagerProxy.getEntityManager(EntityManagerProxy.java:241)

at com.sap.engine.services.orpersistence.container.EntityManagerProxy.createQuery(EntityManagerProxy.java:141)

at test.Test.doGet(Test.java:28)

I am gettting the above exception when I do

<i> em.createQuery("SELECT * FROM S_ORD").getResultList();</i> in servlet's doGet() method.

I am connected to an Oracle database.

Accepted Solutions (1)

Accepted Solutions (1)

adrian_goerler
Employee
Employee
0 Kudos

Hi Vijaysarathi,

The query "SELECT * FROM S_ORD" is no JPQL query. It looks like SQL.

Assuming that you have an entity "MyEntity" mapped to the table S_ORD, you would express this in JPQL like this:

em.createQuery("select m from MyEntity m").getResultList();

Best regards,

Adrian

(The <i>ArrayIndexOutOfBoundsException</i> of an internal error, which should not occur. We will follow up on this issue.)

Former Member
0 Kudos

Hi Adrian,

Thanks for your reply. I tried what you suggested.

em.createQuery("SELECT s FROM SOrd s").getResultList()

I still get the same exception.

No matter what string I give in em.createQuery(..), I get the same exception.

em.createQuery("not a JPQL select query").getResultList()

also gives the same exception.

Former Member
0 Kudos

[code]SQL> desc S_ITEM

Name Null? Type

-


-


-


ORD_ID NOT NULL NUMBER(7)

ITEM_ID NOT NULL NUMBER(7)

PRODUCT_ID NOT NULL NUMBER(7)

PRICE NUMBER(11,2)

QUANTITY NUMBER(9)

QUANTITY_SHIPPED NUMBER(9)

SQL> desc S_Inventory

Name Null? Type

-


-


-


PRODUCT_ID NOT NULL NUMBER(7)

WAREHOUSE_ID NOT NULL NUMBER(7)

AMOUNT_IN_STOCK NUMBER(9)

REORDER_POINT NUMBER(9)

MAX_IN_STOCK NUMBER(9)

OUT_OF_STOCK_EXPLANATION VARCHAR2(255)

RESTOCK_DATE DATE[/code]

I created a fresh EJB3.0 project. Generated an entity for S_ITEM. In a test servlet's doGet() method, I added

[code]em.createQuery("select s from SItem s").getResultList()[/code]

It works fine.

Next I generated another entity for S_Inventory. Synchronized persistence.xml to reflect this change. Made no change in the test servlet.

This time when I access the servlet I get

[code]java.lang.ArrayIndexOutOfBoundsException: -1

at com.sap.engine.services.orpersistence.sqlmapper.common.ExpressionNodeManager.endOfExpression(ExpressionNodeManager.java:2164)

at com.sap.engine.services.orpersistence.sqlmapper.common.EJBLoadStoreBuilder.createBeanLoading(EJBLoadStoreBuilder.java:219)

at com.sap.engine.services.orpersistence.sqlmapper.common.CommonSQLMapper.createEJBSelect(CommonSQLMapper.java:497)

at com.sap.engine.services.orpersistence.sqlmapper.SQLMapperHelper.createQueryDataForFind(SQLMapperHelper.java:57)

at com.sap.engine.services.orpersistence.sqlmapper.SQLMapperHelper.<init>(SQLMapperHelper.java:49)

at com.sap.engine.services.orpersistence.entitymanager.EntityManagerFactoryImpl$MetaDataImpl.<init>(EntityManagerFactoryImpl.java:151)

at com.sap.engine.services.orpersistence.entitymanager.EntityManagerFactoryImpl.getPersistenceUnitData(EntityManagerFactoryImpl.java:124)

at com.sap.engine.services.orpersistence.core.PersistenceContextImpl.<init>(PersistenceContextImpl.java:69)

at com.sap.engine.services.orpersistence.entitymanager.EntityManagerImpl.<init>(EntityManagerImpl.java:71)

at com.sap.engine.services.orpersistence.entitymanager.JtaEntityManagerFactoryImpl.createEntityManagerInternal(JtaEntityManagerFactoryImpl.java:57)

at com.sap.engine.services.orpersistence.entitymanager.JtaEntityManagerFactoryImpl.createEntityManager(JtaEntityManagerFactoryImpl.java:49)

at com.sap.engine.services.orpersistence.container.EMManager.createEntityManager(EMManager.java:202)

at com.sap.engine.services.orpersistence.container.EMManager.getTransactionEntityManager(EMManager.java:77)

at com.sap.engine.services.orpersistence.container.EntityManagerProxy.getEntityManager(EntityManagerProxy.java:241)

at com.sap.engine.services.orpersistence.container.EntityManagerProxy.createQuery(EntityManagerProxy.java:141)

at test.Test.doGet(Test.java:31)[/code]

[code]persistence.xml

<?xml version="1.0" encoding="UTF-8"?>

<persistence xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.0" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd">;

<persistence-unit name="pu3">

<jta-data-source>XA_ORACLE2</jta-data-source>

<class>test2.SInventory</class>

<class>test2.SItem</class>

</persistence-unit>

</persistence>[/code]

Former Member
0 Kudos

Hi!

It would be helpful to have the Java code of you entity classes as well. Could you please post them as well?

Best Regards,

Robin

Former Member
0 Kudos
package test2;
import java.io.Serializable;
import java.math.BigDecimal;
import javax.persistence.Column;
import javax.persistence.Embeddable;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.Table;

@Entity
@Table(name="S_ITEM")
public class SItem implements Serializable {
	@EmbeddedId
	private SItem.PK pk;

	@Column(name="PRODUCT_ID")
	private BigDecimal productId;

	@Column(name="QUANTITY_SHIPPED")
	private BigDecimal quantityShipped;

	private BigDecimal quantity;

	private BigDecimal price;

	private static final long serialVersionUID = 1L;

	public SItem() {
		super();
	}

	public SItem.PK getPk() {
		return this.pk;
	}

	public void setPk(SItem.PK pk) {
		this.pk = pk;
	}

	public BigDecimal getProductId() {
		return this.productId;
	}

	public void setProductId(BigDecimal productId) {
		this.productId = productId;
	}

	public BigDecimal getQuantityShipped() {
		return this.quantityShipped;
	}

	public void setQuantityShipped(BigDecimal quantityShipped) {
		this.quantityShipped = quantityShipped;
	}

	public BigDecimal getQuantity() {
		return this.quantity;
	}

	public void setQuantity(BigDecimal quantity) {
		this.quantity = quantity;
	}

	public BigDecimal getPrice() {
		return this.price;
	}

	public void setPrice(BigDecimal price) {
		this.price = price;
	}


	@Embeddable
	public static class PK implements Serializable {
		private BigDecimal itemId;
		private BigDecimal ordId;
		private static final long serialVersionUID = 1L;

		public PK() {
			super();
		}

		public BigDecimal getItemId() {
			return this.itemId;
		}

		public void setItemId(BigDecimal itemId) {
			this.itemId = itemId;
		}

		public BigDecimal getOrdId() {
			return this.ordId;
		}

		public void setOrdId(BigDecimal ordId) {
			this.ordId = ordId;
		}

		@Override
		public boolean equals(Object o) {
			if (o == this) {
				return true;
			}
			if ( ! (o instanceof PK)) {
				return false;
			}
			PK other = (PK) o;
			return this.itemId.equals(other.itemId)
				&& this.ordId.equals(other.ordId);
		}

		@Override
		public int hashCode() {
			return this.itemId.hashCode()
				^ this.ordId.hashCode();
		}

	}

}


package test2;
import java.io.Serializable;
import java.math.BigDecimal;
import java.sql.Date;
import javax.persistence.Column;
import javax.persistence.Embeddable;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.Table;

@Entity
@Table(name="S_INVENTORY")
public class SInventory implements Serializable {
	@EmbeddedId
	private SInventory.PK pk;

	@Column(name="OUT_OF_STOCK_EXPLANATION")
	private String outOfStockExplanation;

	@Column(name="RESTOCK_DATE")
	private Date restockDate;

	@Column(name="AMOUNT_IN_STOCK")
	private BigDecimal amountInStock;

	@Column(name="REORDER_POINT")
	private BigDecimal reorderPoint;

	@Column(name="MAX_IN_STOCK")
	private BigDecimal maxInStock;

	private static final long serialVersionUID = 1L;

	public SInventory() {
		super();
	}

	public SInventory.PK getPk() {
		return this.pk;
	}

	public void setPk(SInventory.PK pk) {
		this.pk = pk;
	}

	public String getOutOfStockExplanation() {
		return this.outOfStockExplanation;
	}

	public void setOutOfStockExplanation(String outOfStockExplanation) {
		this.outOfStockExplanation = outOfStockExplanation;
	}

	public Date getRestockDate() {
		return this.restockDate;
	}

	public void setRestockDate(Date restockDate) {
		this.restockDate = restockDate;
	}

	public BigDecimal getAmountInStock() {
		return this.amountInStock;
	}

	public void setAmountInStock(BigDecimal amountInStock) {
		this.amountInStock = amountInStock;
	}

	public BigDecimal getReorderPoint() {
		return this.reorderPoint;
	}

	public void setReorderPoint(BigDecimal reorderPoint) {
		this.reorderPoint = reorderPoint;
	}

	public BigDecimal getMaxInStock() {
		return this.maxInStock;
	}

	public void setMaxInStock(BigDecimal maxInStock) {
		this.maxInStock = maxInStock;
	}


	@Embeddable
	public static class PK implements Serializable {
		private BigDecimal warehouseId;
		private BigDecimal productId;
		private static final long serialVersionUID = 1L;

		public PK() {
			super();
		}

		public BigDecimal getWarehouseId() {
			return this.warehouseId;
		}

		public void setWarehouseId(BigDecimal warehouseId) {
			this.warehouseId = warehouseId;
		}

		public BigDecimal getProductId() {
			return this.productId;
		}

		public void setProductId(BigDecimal productId) {
			this.productId = productId;
		}

		@Override
		public boolean equals(Object o) {
			if (o == this) {
				return true;
			}
			if ( ! (o instanceof PK)) {
				return false;
			}
			PK other = (PK) o;
			return this.warehouseId.equals(other.warehouseId)
				&& this.productId.equals(other.productId);
		}

		@Override
		public int hashCode() {
			return this.warehouseId.hashCode()
				^ this.productId.hashCode();
		}

	}

}
Former Member
0 Kudos

code in my Test Servlet

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		response.getWriter().println("records="+ em.createQuery("select s from SItem s").getResultList());
	}  	

Former Member
0 Kudos

Hi!

Thanks for the additional information. We have reconstructed you scenario successfully and are currently investigating the issue.

You could try to use your embeddedID field with a class that is not an inner class to your entity class as a workaround since we suspect that the root for your issue lies somewhere in this area. However, the JPQL query that you create here has nothing to do with the exception that is thrown.

Best Regards,

Robin

Former Member
0 Kudos

Thanks Robin.

I will try the workaround you suggested.

My tables also have the following database constraints.

Constraints on S_ITEM

CONSTRAINT_NAME                COLUMN_NAME          Constraint_type
------------------------------ -------------------- -
S_ITEM_ORD_ID_NN               ORD_ID               C
S_ITEM_ITEM_ID_NN              ITEM_ID              C
S_ITEM_PRODUCT_ID_NN           PRODUCT_ID           C
S_ITEM_ORDID_ITEMID_PK         ORD_ID               P
S_ITEM_ORDID_ITEMID_PK         ITEM_ID              P
S_ITEM_ORDID_PRODID_UK         ORD_ID               U
S_ITEM_ORDID_PRODID_UK         PRODUCT_ID           U
S_ITEM_ORD_ID_FK               ORD_ID               R
S_ITEM_PRODUCT_ID_FK           PRODUCT_ID           R


Constraints on S_INVENTORY

CONSTRAINT_NAME                COLUMN_NAME          Constraint_type
------------------------------ -------------------- -
S_INVENTORY_PRODUCT_ID_NN      PRODUCT_ID           C
S_INVENTORY_WAREHOUSE_ID_NN    WAREHOUSE_ID         C
S_INVENTORY_PRODID_WARID_PK    PRODUCT_ID           P
S_INVENTORY_PRODID_WARID_PK    WAREHOUSE_ID         P
S_INVENTORY_PRODUCT_ID_FK      PRODUCT_ID           R
S_INVENTORY_WAREHOUSE_ID_FK    WAREHOUSE_ID         R



(NN -> NOT NULL, PK-> Primary Key, FK -> Foreign Key)

Former Member
0 Kudos

Hi Robin,

I tried the workaround you suggested. It did not work. I am getting the same exception.

Thank you,

Vijay.

Former Member
0 Kudos

Hi!

We investigated your problem and came to the following solution:

Since the fields of your embeddable class are also mapped to your S_ITEM table and differ from the default naming (column name == field name) you have to specify the specific column names with the @Column annotation as you did in your entity class.

[code]

@Embeddable

public static class PK implements Serializable {

@Column(name="ITEM_ID")

private BigDecimal itemId;

@Column(name="ORD_ID")

private BigDecimal ordId;

...

[/code]

Additionally to that you should also add the following element to your persistence.xml:

[code]

<class>test2.SItem$PK</class>

[/code]

This should help you to get your code working. However the error-message was absolutey misleading. We will on a improved error-message for issues like this.

There is another remark about the FK constraints. The JPA specification is not specific about the use of FK on the database. The behavior of a given JPA application based on a DB schema with FK constraints is not predictable from our side. If you experience any unexpected behavior with your JPA application we would welcome any feedback from your side.

Best Regards,

Robin

Former Member
0 Kudos

Thanks Robin. It solved my problem.

I will let you know if I face any problems with FK constraints.

Also, I used

EJB3.0 Project’s Java Persistence->Generate Entities

wizards to generate my entities and the wizard is not generating @Column mappings for inner classes.

Thanks a Lot,

Vijay.

Answers (1)

Answers (1)

Former Member
0 Kudos

Hi!

The Dali plugin that is used for JPA code-generation in our IDE is known to be not complete, yet. The version that is used here is 0.5x. If you want to be 100% sure with your JPA code you have to write it by hand.

Best Regards,

Robin