Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[eclipselink-users] JPQL: when embedded class is used in LHS of In clause DB Exception occurs

Problem Statement:
------------------
1. In JPQL, when embedded class is used in LHS of In clause DB Exception
occurs.
2. In example depicted below, entity 'Domain' has embedded-id 'DomainKey',
which contains 2 attributes: domainId and domainVersion.
3. If JPQL with 'IN' clause is fired on 'domainKey' attribute it fails.
   For example, select a from learning.entity.Domain a where a.domainKey in
:domainKeys
   Above query fails with Exception: java.sql.SQLException: Invalid column
type
   
Example explaining the above scenario:
--------------------------------------

Entities:
---------
package learning.entity;


public class Domain  {
	
	private DomainKey domainKey;
	
	/**
	 * Attribute specifies user friendly name of domain.
	 */
    private String name;

    /**
	 * Attribute specifies description of domain.
	 */
    private String description;
   

	public DomainKey getDomainKey() {
		return domainKey;
	}

	public void setDomainKey(DomainKey domainKey) {
		this.domainKey = domainKey;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}
}


package learning.entity;

public class DomainKey {

	private String domainId;
	private int domainVersion;

	public String getDomainId() {

		return domainId;
	}

	public void setDomainId(String domainId) {

		this.domainId = domainId;
	}

	/**
	 * @return the domainVersion
	 */
	public int getDomainVersion() {

		return domainVersion;
	}

	/**
	 * @param domainVersion
	 *            the domainVersion to set
	 */
	public void setDomainVersion(int domainVersion) {

		this.domainVersion = domainVersion;
	}
}

Mappings:
---------
<?xml version="1.0" encoding="UTF-8"?>
<entity-mappings version="2.4"
	xmlns="http://www.eclipse.org/eclipselink/xsds/persistence/orm";
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
	xsi:schemaLocation="http://www.eclipse.org/eclipselink/xsds/persistence/orm
http://www.eclipse.org/eclipselink/xsds/eclipselink_orm_2_4.xsd";>

	<entity class="learning.entity.Domain">
		

		

		<attributes>
			<embedded-id attribute-type="learning.entity.DomainKey"
				name="domainKey">
				<attribute-override name="domainId">
					<column name="DOMAIN_CODE" />
				</attribute-override>
				<attribute-override name="domainVersion">
					<column name="DOMAIN_VERSION" />
				</attribute-override>
			</embedded-id>
			<basic name="name">
				<column name="DOMAIN_NAME" />
			</basic>
			<basic name="description">
				<column name="DOMAIN_DESC" />
			</basic>
		</attributes>
	</entity>

	<embeddable class="learning.entity.DomainKey">
		<attributes>
			<basic attribute-type="java.lang.String" name="domainId" />
			<basic attribute-type="int" name="domainVersion" />
		</attributes>
	</embeddable>
</entity-mappings>

Tables:
-------
create table TST_DOMAINS_B
(
  DOMAIN_CODE    VARCHAR2(100),
  DOMAIN_NAME    VARCHAR2(100),
  DOMAIN_DESC    VARCHAR2(100),
  DOMAIN_VERSION NUMBER
)

Test Case:
----------
package learning.service;

import java.util.ArrayList;
import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
import javax.persistence.Query;

import learning.entity.DomainKey;

public class EclipseLinkJPATest {

	public static void main(String[] args) {

		EntityManagerFactory entityManagerFactory =
Persistence.createEntityManagerFactory("MyEclipseLinkJPALearning");
		EntityManager entityManager = entityManagerFactory.createEntityManager();
		Query q = entityManager.createQuery("select a from learning.entity.Domain
a where a.domainKey in :domainKeys");
		DomainKey key1 = new DomainKey();
		key1.setDomainId("Finance");
		key1.setDomainVersion(1);
		DomainKey key2 = new DomainKey();
		key2.setDomainId("Telecom");
		key2.setDomainVersion(1);
		ArrayList<DomainKey> domainKeys = new ArrayList<DomainKey>();
		domainKeys.add(key1);
		domainKeys.add(key2);
		q.setParameter("domainKeys", domainKeys);
		List data = q.getResultList();
		System.out.println("query result: " + data);
	}
}

Exception Log:
--------------
Exception in thread "main" javax.persistence.PersistenceException: Exception
[EclipseLink-4002] (Eclipse Persistence Services - 2.5.1.v20130918-f2b9fc5):
org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: java.sql.SQLException: Invalid column type
Error Code: 17004
Call: SELECT DOMAIN_DESC, DOMAIN_NAME, DOMAIN_CODE, DOMAIN_VERSION FROM
TST_DOMAINS_B WHERE ((?, ?) IN (?,?))
	bind => [null, null, DomainKey [domainId=Finance, domainVersion=1],
DomainKey [domainId=Telecom, domainVersion=1]]
Query: ReportQuery(referenceClass=Domain sql="SELECT DOMAIN_DESC,
DOMAIN_NAME, DOMAIN_CODE, DOMAIN_VERSION FROM TST_DOMAINS_B WHERE ((?, ?) IN
?)")
	at
org.eclipse.persistence.internal.jpa.QueryImpl.getDetailedException(QueryImpl.java:378)
	at
org.eclipse.persistence.internal.jpa.QueryImpl.executeReadQuery(QueryImpl.java:260)
	at
org.eclipse.persistence.internal.jpa.QueryImpl.getResultList(QueryImpl.java:469)
	at learning.service.EclipseLinkJPATest.main(EclipseLinkJPATest.java:31)
Caused by: Exception [EclipseLink-4002] (Eclipse Persistence Services -
2.5.1.v20130918-f2b9fc5):
org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: java.sql.SQLException: Invalid column type
Error Code: 17004
Call: SELECT DOMAIN_DESC, DOMAIN_NAME, DOMAIN_CODE, DOMAIN_VERSION FROM
TST_DOMAINS_B WHERE ((?, ?) IN (?,?))
	bind => [null, null, DomainKey [domainId=Finance, domainVersion=1],
DomainKey [domainId=Telecom, domainVersion=1]]
Query: ReportQuery(referenceClass=Domain sql="SELECT DOMAIN_DESC,
DOMAIN_NAME, DOMAIN_CODE, DOMAIN_VERSION FROM TST_DOMAINS_B WHERE ((?, ?) IN
?)")
	at
org.eclipse.persistence.exceptions.DatabaseException.sqlException(DatabaseException.java:340)
	at
org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.basicExecuteCall(DatabaseAccessor.java:682)
	at
org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.executeCall(DatabaseAccessor.java:558)
	at
org.eclipse.persistence.internal.sessions.AbstractSession.basicExecuteCall(AbstractSession.java:1991)
	at
org.eclipse.persistence.sessions.server.ServerSession.executeCall(ServerSession.java:570)
	at
org.eclipse.persistence.internal.queries.DatasourceCallQueryMechanism.executeCall(DatasourceCallQueryMechanism.java:242)
	at
org.eclipse.persistence.internal.queries.DatasourceCallQueryMechanism.executeCall(DatasourceCallQueryMechanism.java:228)
	at
org.eclipse.persistence.internal.queries.DatasourceCallQueryMechanism.executeSelectCall(DatasourceCallQueryMechanism.java:299)
	at
org.eclipse.persistence.internal.queries.DatasourceCallQueryMechanism.selectAllRows(DatasourceCallQueryMechanism.java:694)
	at
org.eclipse.persistence.internal.queries.ExpressionQueryMechanism.selectAllRowsFromTable(ExpressionQueryMechanism.java:2738)
	at
org.eclipse.persistence.internal.queries.ExpressionQueryMechanism.selectAllReportQueryRows(ExpressionQueryMechanism.java:2675)
	at
org.eclipse.persistence.queries.ReportQuery.executeDatabaseQuery(ReportQuery.java:848)
	at
org.eclipse.persistence.queries.DatabaseQuery.execute(DatabaseQuery.java:899)
	at
org.eclipse.persistence.queries.ObjectLevelReadQuery.execute(ObjectLevelReadQuery.java:1127)
	at
org.eclipse.persistence.queries.ReadAllQuery.execute(ReadAllQuery.java:403)
	at
org.eclipse.persistence.queries.ObjectLevelReadQuery.executeInUnitOfWork(ObjectLevelReadQuery.java:1215)
	at
org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.internalExecuteQuery(UnitOfWorkImpl.java:2896)
	at
org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1793)
	at
org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1775)
	at
org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1740)
	at
org.eclipse.persistence.internal.jpa.QueryImpl.executeReadQuery(QueryImpl.java:258)
	... 2 more
Caused by: java.sql.SQLException: Invalid column type
	at
oracle.jdbc.driver.OraclePreparedStatement.setObjectCritical(OraclePreparedStatement.java:8921)
	at
oracle.jdbc.driver.OraclePreparedStatement.setObjectInternal(OraclePreparedStatement.java:8396)
	at
oracle.jdbc.driver.OraclePreparedStatement.setObjectInternal(OraclePreparedStatement.java:9176)
	at
oracle.jdbc.driver.OraclePreparedStatement.setObject(OraclePreparedStatement.java:9153)
	at
oracle.jdbc.driver.OraclePreparedStatementWrapper.setObject(OraclePreparedStatementWrapper.java:234)
	at
org.eclipse.persistence.internal.databaseaccess.DatabasePlatform.setParameterValueInDatabaseCall(DatabasePlatform.java:2441)
	at
org.eclipse.persistence.platform.database.oracle.Oracle9Platform.setParameterValueInDatabaseCall(Oracle9Platform.java:525)
	at
org.eclipse.persistence.internal.databaseaccess.DatabaseCall.prepareStatement(DatabaseCall.java:797)
	at
org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.basicExecuteCall(DatabaseAccessor.java:619)
	... 21 more



--
View this message in context: http://eclipse.1072660.n5.nabble.com/JPQL-when-embedded-class-is-used-in-LHS-of-In-clause-DB-Exception-occurs-tp167488.html
Sent from the EclipseLink - Users mailing list archive at Nabble.com.


Back to the top