Delete query

I get an exception when performing a delete with jpql.

Why doesn't the parameter ContactId get interpreted?

Here is exception and relevant code:

Servlet.log:

at com.sun.enterprise.web.connector.grizzly.TaskBase.run(TaskBase.java:252)

at com.sun.enterprise.web.connector.grizzly.WorkerThread.run(WorkerThread.java:75)

Caused by: Exception [TOPLINK-4002] (Oracle TopLink Essentials - 2006.4 (Build 060412)): oracle.toplink.essentials.exceptions.DatabaseException

Internal Exception: org.apache.derby.client.am.SqlException: Syntax error: Encountered"=" at line 1, column 46.Error Code: -1

Call:DELETE FROM WVID WHERE ((LISTNAME = ?) AND ( = ?))

bind => [tobiassen1/default@meldingssentralen.no, no.tobiassen.entities.Users[id=1]]

Query:DeleteAllQuery()

at oracle.toplink.essentials.exceptions.DatabaseException.sqlException(DatabaseException.java:303)

at oracle.toplink.essentials.internal.databaseaccess.DatabaseAccessor.basicExecuteCall(DatabaseAccessor.java:551)

at no.tobiassen.sessions.WVFacadeBean.deleteWVID(WVFacadeBean.java:170)

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

at java.lang.reflect.Method.invoke(Method.java:585)

at com.sun.enterprise.security.application.EJBSecurityManager.runMethod(EJBSecurityManager.java:1050)

at com.sun.enterprise.security.SecurityUtil.invoke(SecurityUtil.java:165)

at com.sun.ejb.containers.BaseContainer.invokeTargetBeanMethod(BaseContainer.java:2766)

at com.sun.ejb.containers.BaseContainer.intercept(BaseContainer.java:3847)

at com.sun.ejb.containers.EJBLocalObjectInvocationHandler.invoke(EJBLocalObjectInvocationHandler.java:184)

... 32 more

Caused by: org.apache.derby.client.am.SqlException: Syntax error: Encountered"=" at line 1, column 46.

at org.apache.derby.client.am.Statement.completeSqlca(Unknown Source)

Code:

WVID:

@Entity

publicclass WVIDimplements Serializable{

@Id

@GeneratedValue(strategy = GenerationType.AUTO)

private Long id;

@OneToOne

private Users Owner;//Owner is the owner of all the ContactIds in a list

private String ListName;

private String Name;

@OneToOne

private Users ContactId;

/** Creates a new instance of WVID */

public WVID(){

}

public WVID(Users owner, String listName, String name, Users contactId){

this.Owner=owner;

this.ListName=listName;

this.Name=name;

this.ContactId=contactId;

}

/**

* Gets the id of this WVID.

* @return the id

*/

public Long getId(){

return this.id;

}

/**

* Sets the id of this WVID to the specified value.

* @param id the new id

*/

publicvoid setId(Long id){

this.id = id;

}

public Users getContactId(){

return ContactId;

}

publicvoid setContactId(Users ContactId){

this.ContactId = ContactId;

}

publicvoid setOwner(Users Owner){

this.Owner = Owner;

}

publicvoid setName(String Name){

this.Name = Name;

}

publicvoid setListName(String ListName){

this.ListName = ListName;

}

public Users getOwner(){

return Owner;

}

public String getName(){

return Name;

}

public String getListName(){

return ListName;

}

/**

* Returns a hash code value for the object. This implementation computes

* a hash code value based on the id fields in this object.

* @return a hash code value for this object.

*/

@Override

publicint hashCode(){

int hash = 0;

hash += (this.id !=null ? this.id.hashCode() : 0);

return hash;

}

/**

* Determines whether another object is equal to this WVID. The result is

* <code>true</code> if and only if the argument is not null and is a WVID object that

* has the same id field values as this object.

* @param object the reference object with which to compare

* @return <code>true</code> if this object is the same as the argument;

* <code>false</code> otherwise.

*/

@Override

publicboolean equals(Object object){

// TODO: Warning - this method won't work in the case the id fields are not set

if (!(objectinstanceof WVID)){

returnfalse;

}

WVID other = (WVID)object;

if (this.id != other.id && (this.id ==null || !this.id.equals(other.id)))returnfalse;

returntrue;

}

/**

* Returns a string representation of the object. This implementation constructs

* that representation based on the id fields.

* @return a string representation of the object.

*/

@Override

public String toString(){

return"no.tobiassen.entities.WVID[id=" + id +"]";

}

}

WVFacadeBean:

@Stateless

publicclass WVFacadeBeanimplements no.tobiassen.sessions.WVFacadeLocal{

....

publicvoid deleteWVID(String userId, java.lang.String sessionId, String contactList){

Users user=null;

if(sessionId==null){

user=getUser(userId);

}

if(userId==null){

user=getSession(sessionId,null).getUsers();

}

em.createQuery("DELETE FROM WVID w WHERE w.ListName=?1 AND w.ContactId=?2").setParameter(2, user).setParameter(1, contactList).executeUpdate();

}

[9171 byte] By [tobiassen666a] at [2007-11-27 5:55:55]
# 1
http://forum.java.sun.com/thread.jspa?threadID=5179694&messageID=9697853#9697853
tobiassen666a at 2007-7-12 16:25:25 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...