Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » ConversionException When Using Enum in Composite Primary Keys(ConversionException When Using Enum in Composite Primary Keys)
ConversionException When Using Enum in Composite Primary Keys [message #1063171] Wed, 12 June 2013 14:15 Go to next message
Aslam Ahmed is currently offline Aslam AhmedFriend
Messages: 3
Registered: June 2013
Junior Member
Hello Everyone,
I am using enum plus long field as my composite primary key in a model. But when I use both of the fields in jpql for filter criteria (e.g. where modelId = ?1 and vendorType = ?2) it gives me a ConversionException. Appreciate if someone can clarify. Below are the details:

VendorView:
@MappedSuperclass

@IdClass(VendorPK.class)
public abstract class VendorView extends AbstractView {	

	private static final long serialVersionUID = 4952393420338697658L;
	
	@Id
	@Column(name="MODEL_XID")
	protected Long modelId;
	
	@Id
	@Enumerated
	@Column(name="VENDOR_TYPE")	
	protected VendorType vendorType;
	
	@Column(name="CODE")
	@ReportElement(name="Code",dataType=DataType.TEXT,filter=true,index=1,sort=true,zlist=true,width=75)
	protected String code;
	
	@Column(name="SHORT_NAME")
	@ReportElement(name="Short Name",dataType=DataType.TEXT,filter=true,index=1,sort=true)
	protected String shortName;
	
	@Column(name="TITLE")
	@ReportElement(name="Title",dataType=DataType.TEXT,filter=true,index=0,sort=true,zlist=true,width=200)
	protected String title;
	
	@Column(name="DESCRIPTION")
	protected String description;		
		
	@Column(name="APPLY_CHARGES")
	@ReportElement(name="Apply charges",dataType=DataType.BOOLEAN,filter=true,index=3,sort=true)
	protected Boolean applyCharges; 
	
	@Column(name="ADDRESS1")
	@ReportElement(name="Address",dataType=DataType.TEXT,filter=false,index=4,sort=false)
	protected String address1;
	
	@Column(name="ADDRESS2")
	protected String address2;
	
	@Column(name="PHONE1")  	
	@ReportElement(name="Phone",dataType=DataType.TEXT,filter=false,index=5,sort=false)
	protected String phone1; 
	
	@Column(name="PHONE2")
	protected String phone2;
	
	@Column(name="FAX")
	@ReportElement(name="Fax",dataType=DataType.TEXT,filter=false,index=6,sort=false)
	protected String fax;

	
	
	public Long getModelId() {
		return modelId;
	}
	
	public String getCode() {
		return code;
	}

	public String getShortName() {
		return shortName;
	}
	
	public String getTitle() {
		return title;
	}


	public String getDescription() {
		return description;
	}

	
	public Boolean isApplyCharges() {
		return applyCharges;
	}


	public String getAddress1() {
		return address1;
	}


	public String getAddress2() {
		return address2;
	}


	public String getPhone1() {
		return phone1;
	}


	public String getPhone2() {
		return phone2;
	}


	public String getFax() {
		return fax;
	}

	public VendorType getVendorType() {
		return vendorType;
	}
	
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((modelId == null) ? 0 : modelId.hashCode());
		result = prime * result
				+ ((vendorType == null) ? 0 : vendorType.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;		
		if (getClass() != obj.getClass())
			return false;
		VendorView other = (VendorView) obj;
		if (modelId == null) {
			if (other.modelId != null)
				return false;
		} else if (!modelId.equals(other.modelId))
			return false;
		if (vendorType == null) {
			if (other.vendorType != null)
				return false;
		} else if (!vendorType.equals(other.vendorType))
			return false;
		return true;
	}
}


VendorPk:
@Embeddable
public class VendorPK implements Serializable{

	private static final long serialVersionUID = 2313226839954294852L;

	@Column(name="MODEL_XID")
	protected Long modelId;
	
	@Column(name="VENDOR_TYPE")
	@Enumerated
	protected VendorType vendorType;
	
	public VendorPK(){}
	
	public VendorPK(Long modelId, VendorType vendorType){
		this.modelId = modelId;
		this.vendorType = vendorType;
	}

	public Long getModelId() {
		return modelId;
	}

	public void setModelId(Long modelId) {
		this.modelId = modelId;
	}
	
	public VendorType getVendorType() {
		return vendorType;
	}

	public void setVendorType(VendorType vendorType) {
		this.vendorType = vendorType;
	}

	public int hashCode() {
        return (int)(Long.valueOf(modelId).hashCode()) + this.vendorType.hashCode();
    }

    
	public boolean equals(Object obj) {
		if (obj == null) return false;
		if (obj == this) return true;
        if (!(obj instanceof VendorPK)) return false;
        VendorPK pk = (VendorPK) obj;
        return ((pk.modelId==this.modelId) && pk.vendorType.equals(this.vendorType));
    }
}


AirlineView:
@Entity
@Table(name="GBOSSV_VENDOR")

@SecurityContext(value=Airline.class)

public class AirlineView extends VendorView {
	
	private static final long serialVersionUID = 2969582818437459745L;
	
	@Column(name="DIGIT_CODE")
	@ReportElement(name="Digit Code",dataType=DataType.TEXT,width=50,filter=true,index=7,sort=true,zlist=true)
	protected String digitCode;
	
	@Column(name="CHARACTER_CODE")
	@ReportElement(name="Character Code",dataType=DataType.TEXT,width=50,filter=true,index=8,sort=true,zlist=true)
	protected String characterCode; 
	
	@Column(name="IS_IATA")
	@ReportElement(name="Is IATA",dataType=DataType.BOOLEAN,filter=true,index=9,sort=true)
	protected Boolean IATA;

	public String getDigitCode() {
		return digitCode;
	}

	public String getCharacterCode() {
		return characterCode;
	}

	public Boolean getIATA() {
		return IATA;
	}

}



Jpql:
SELECT m FROM AirlineView m  WHERE m.modelId =?1 and m.vendorType = ?2 ORDER BY m.vendorType,m.modelId ASC


StackTrace
[org.eclipse.persistence.exceptions.ConversionException.couldNotBeConverted(ConversionException.java:71), org.eclipse.persistence.internal.helper.ConversionManager.convertObjectToInteger(ConversionManager.java:543), org.eclipse.persistence.internal.helper.ConversionManager.convertObject(ConversionManager.java:114), org.eclipse.persistence.internal.databaseaccess.DatasourcePlatform.convertObject(DatasourcePlatform.java:162), org.eclipse.persistence.internal.descriptors.ObjectBuilder.extractPrimaryKeyFromRow(ObjectBuilder.java:2545), org.eclipse.persistence.internal.descriptors.ObjectBuilder.extractPrimaryKeyFromExpression(ObjectBuilder.java:2392), org.eclipse.persistence.internal.queries.ExpressionQueryMechanism.checkCacheForObject(ExpressionQueryMechanism.java:866), org.eclipse.persistence.queries.ReadObjectQuery.checkEarlyReturnLocal(ReadObjectQuery.java:243), org.eclipse.persistence.queries.ObjectLevelReadQuery.checkEarlyReturn(ObjectLevelReadQuery.java:838), org.eclipse.persistence.queries.DatabaseQuery.execute(DatabaseQuery.java:789), org.eclipse.persistence.queries.ObjectLevelReadQuery.execute(ObjectLevelReadQuery.java:1109), org.eclipse.persistence.queries.ReadObjectQuery.execute(ReadObjectQuery.java:421), org.eclipse.persistence.queries.ObjectLevelReadQuery.executeInUnitOfWork(ObjectLevelReadQuery.java:1197), org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.internalExecuteQuery(UnitOfWorkImpl.java:2875), org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1602), org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1584), org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1549), org.eclipse.persistence.internal.jpa.QueryImpl.executeReadQuery(QueryImpl.java:231), org.eclipse.persistence.internal.jpa.QueryImpl.getResultList(QueryImpl.java:403), com.bnv.zinro.node.Dao.readList(Dao.java:162), sun.reflect.GeneratedMethodAccessor21.invoke(Unknown Source), sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25), java.lang.reflect.Method.invoke(Method.java:597), org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:317), org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183), org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150), org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:110), org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172), org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204), $Proxy51.readList(Unknown Source), sun.reflect.GeneratedMethodAccessor21.invoke(Unknown Source), sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25), java.lang.reflect.Method.invoke(Method.java:597), org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:317), org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183), org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150), org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:110), org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172), org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204), $Proxy52.readList(Unknown Source), com.bnv.zinro.node.TransactionalModelManager.getViewList(TransactionalModelManager.java:114), sun.reflect.GeneratedMethodAccessor20.invoke(Unknown Source), sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25), java.lang.reflect.Method.invoke(Method.java:597), org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:317), org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183), org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150), org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:110), org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172), org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204), $Proxy53.getViewList(Unknown Source), sun.reflect.GeneratedMethodAccessor20.invoke(Unknown Source), sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25), java.lang.reflect.Method.invoke(Method.java:597), org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:317), org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183), org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150), org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:110), org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172), org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204), $Proxy53.getViewList(Unknown Source), com.bnv.zinro.node.ModelManager.getViewList(ModelManager.java:141), com.bnv.zinro.node.RemoteManager.getViewList(RemoteManager.java:264), sun.reflect.GeneratedMethodAccessor25.invoke(Unknown Source), sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25), java.lang.reflect.Method.invoke(Method.java:597), sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:305), sun.rmi.transport.Transport$1.run(Transport.java:159), java.security.AccessController.doPrivileged(Native Method), sun.rmi.transport.Transport.serviceCall(Transport.java:155), sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:535), sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:790), sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:649), java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886), java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908), java.lang.Thread.run(Thread.java:619)]
Re: ConversionException When Using Enum in Composite Primary Keys [message #1064274 is a reply to message #1063171] Tue, 18 June 2013 14:14 Go to previous messageGo to next message
James Sutherland is currently offline James SutherlandFriend
Messages: 1939
Registered: July 2009
Location: Ottawa, Canada
Senior Member

Please include the error message.

James : Wiki : Book : Blog : Twitter
Re: ConversionException When Using Enum in Composite Primary Keys [message #1064398 is a reply to message #1064274] Wed, 19 June 2013 05:44 Go to previous messageGo to next message
Aslam Ahmed is currently offline Aslam AhmedFriend
Messages: 3
Registered: June 2013
Junior Member
James Sutherland wrote on Tue, 18 June 2013 10:14
Please include the error message.


Here it is.
[ZFME=FW_CO_100, ZMsg=Database Exception , addMsg=
Exception Description: The object [AIRLINE], of class [class com.bnv.zinro.catalyst.model.vendor.VendorType], could not be converted to [class java.lang.Integer].
, Ref=null, getMessage()=null, getCause()=null]


VendorType:
public enum VendorType {

	AIRLINE("Airline"),
	HOTEL("Hotel"),
	TRANSPORT("Transport"),
	VISA("Visa"),
	GENERAL(IGbossConstants.GENERAL);
	
	String title;
	
	private VendorType(String title){
		this.title = title;
	}
	
	public String getTitle(){
		return title;
	}

	
}

[Updated on: Wed, 19 June 2013 05:46]

Report message to a moderator

Re: ConversionException When Using Enum in Composite Primary Keys [message #1065372 is a reply to message #1064398] Tue, 25 June 2013 13:28 Go to previous messageGo to next message
James Sutherland is currently offline James SutherlandFriend
Messages: 1939
Registered: July 2009
Location: Ottawa, Canada
Senior Member

Odd, is should be getting converted when extracted from the Expression. Can you try a find() does it work?

Could be a bug, if you can isolate a test case, and recreate it on the latest release (2.5), then please log a bug.

As a workaround you can either use find() or set the query hint, "eclipselink.cache-usage"="DoNotCheckCache"


James : Wiki : Book : Blog : Twitter
Re: ConversionException When Using Enum in Composite Primary Keys [message #1065489 is a reply to message #1065372] Wed, 26 June 2013 05:17 Go to previous message
Aslam Ahmed is currently offline Aslam AhmedFriend
Messages: 3
Registered: June 2013
Junior Member
James Sutherland wrote on Tue, 25 June 2013 09:28
Odd, is should be getting converted when extracted from the Expression. Can you try a find() does it work?

Could be a bug, if you can isolate a test case, and recreate it on the latest release (2.5), then please log a bug.

As a workaround you can either use find() or set the query hint, "eclipselink.cache-usage"="DoNotCheckCache"


Well I somehow manage to resolve the problem, but I will see what can I do with the test case and bug reporting since I am not very good with them, any way thanks for your help.
Previous Topic:JPA Mapping Multi-Rows with ElementCollection
Next Topic:java.lang.ArrayIndexOutOfBoundsException: -1
Goto Forum:
  


Current Time: Fri Apr 26 18:28:39 GMT 2024

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

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

Back to the top