-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 9 posts ] 
Author Message
 Post subject: TypeMismatchException
PostPosted: Sat Oct 06, 2007 12:48 am 
Newbie

Joined: Thu Oct 04, 2007 5:00 am
Posts: 13
Hibernate version:3.2
b]Tables in database:[/b]
Users
email VARCHAR(200) primary key
nameid bigint foreign key to Name table

Name
nameid bigint primary key
firstname VARCHAR(50)
middlename VARCHAR(50)
lastname VARCHAR(50)

Mapping documents:
users.hbm.xml
<class name="hibernate.pojo.Users" table="USERS">
<id name="emailid" column="EMAILID">
<generator class="assigned"/>
</id>

<!--unidirectional one-to-one mappings from User to Name-->
<one-to-one name="name" class="hibernate.pojo.Name" foreign-key="nameid" fetch="join"/>
</class>

Name.hbm.xml
<hibernate-mapping>
<class name="hibernate.pojo.Name" table="NAME">
<id name="nameid" column="NAMEID">
<generator class="increment"/>
</id>
<property name="title" column="TITLE"/>
<property name="firstname" column="FIRSTNAME"/>
<property name="lastname" column="LASTNAME"/>
</class>
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close():
String queryString = "from hibernate.pojo.Users";

Query query = session.createQuery ( queryString );


List<Users> list = ( List<Users> ) query.list();


Full stack trace of any exception that occurs:
org.hibernate.TypeMismatchException: Provided id of the wrong type. Expected: class java.lang.Long, got class java.lang.String
at org.hibernate.event.def.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:86)
at org.hibernate.impl.SessionImpl.fireLoad(SessionImpl.java:878)
at org.hibernate.impl.SessionImpl.internalLoad(SessionImpl.java:846)
at org.hibernate.type.EntityType.resolveIdentifier(EntityType.java:557)
at org.hibernate.type.EntityType.resolve(EntityType.java:379)
at org.hibernate.engine.TwoPhaseLoad.initializeEntity(TwoPhaseLoad.java:116)
at org.hibernate.loader.Loader.initializeEntitiesAndCollections(Loader.java:854)
at org.hibernate.loader.Loader.doQuery(Loader.java:729)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:236)
at org.hibernate.loader.Loader.doList(Loader.java:2220)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2104)
at org.hibernate.loader.Loader.list(Loader.java:2099)
at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:378)
at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:338)
at org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:172)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1121)
at org.hibernate.impl.QueryImpl.list(QueryImpl.java:79)
at helpers.DuplicateUserCheck.isDuplicateUser(DuplicateUserCheck.java:37)
at struts.action.AbstractUserRegistrationAction.execute(AbstractUserRegistrationAction.java:196)
at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:431)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:236)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196)
at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:432)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
at org.apache.catalina.core.ApplicationFilterChain.servletService(ApplicationFilterChain.java:397)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:278)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:566)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:536)
at org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:240)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:179)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:566)
at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:73)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:182)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:566)
at com.sun.enterprise.web.VirtualServerPipeline.invoke(VirtualServerPipeline.java:120)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:939)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:137)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:566)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:536)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:939)
at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:239)
at com.sun.enterprise.web.connector.grizzly.ProcessorTask.invokeAdapter(ProcessorTask.java:667)
at com.sun.enterprise.web.connector.grizzly.ProcessorTask.processNonBlocked(ProcessorTask.java:574)
at com.sun.enterprise.web.connector.grizzly.ProcessorTask.process(ProcessorTask.java:844)
at com.sun.enterprise.web.connector.grizzly.ReadTask.executeProcessorTask(ReadTask.java:287)
at com.sun.enterprise.web.connector.grizzly.ReadTask.doTask(ReadTask.java:212)
at com.sun.enterprise.web.connector.grizzly.TaskBase.run(TaskBase.java:252)
at com.sun.enterprise.web.connector.grizzly.WorkerThread.run(WorkerThread.java:75)


Name and version of the database you are using:JavaDB 10.2.2

The generated SQL (show_sql=true):


Top
 Profile  
 
 Post subject:
PostPosted: Sat Oct 06, 2007 6:19 pm 
Regular
Regular

Joined: Sun Sep 30, 2007 7:51 pm
Posts: 93
Post the classes (User, Name).

regards,
Pavol


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 08, 2007 12:09 am 
Newbie

Joined: Thu Oct 04, 2007 5:00 am
Posts: 13
POJO classes
Users.java
public class Users {
private String emailid;
private Name name;

public String getEmailid() {
return this.emailid;
}

public void setEmailid(String emailid) {
this.emailid = emailid;
}

public Name getName() {
return this.name;
}

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

Name.java
public class Name {
private long nameid;
private String title;
private String firstname;
private String lastname;

public long getNameid() {
return this.nameid;
}

public void setNameid(long nameid) {
this.nameid = nameid;
}

public void setTitle(String title) {
this.title = title;
}

public String getTitle() {
return this.title;
}

public String getFirstname() {
return this.firstname;
}

public void setFirstname(String firstname) {
this.firstname = firstname;
}

public String getLastname() {
return this.lastname;
}


public void setLastname(String lastname) {
this.lastname = lastname;
}

}


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 08, 2007 12:41 am 
Regular
Regular

Joined: Sun Sep 30, 2007 7:51 pm
Posts: 93
Well I don't know. Seems ok.

Sorry I could not help,
Pavol


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 08, 2007 3:17 am 
Newbie

Joined: Tue Nov 28, 2006 4:34 am
Posts: 5
In users.hbm.xml try to set the type of the ID:
Code:
<class name="hibernate.pojo.Users" table="USERS">
<id name="emailid" column="EMAILID" [color=red]type="string"[/color]>
<generator class="assigned"/>
</id>


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 08, 2007 5:23 am 
Newbie

Joined: Mon Oct 01, 2007 8:59 am
Posts: 18
use this code it will help you.

<class name="hibernate.pojo.Users" table="USERS">
<id name="emailid" column="EMAILID" type="string">
<generator class="assigned"/>
</id>


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 09, 2007 12:36 am 
Newbie

Joined: Thu Oct 04, 2007 5:00 am
Posts: 13
No, that doesn't make any difference, application still throws TypeMismatchException. I debugged the program:-
while retriving the data from database control, goes to the Users class (POJO class), then goes into setEmailid() method and assigns retrived emailid to the class's emailid instance variable. When it comes out of this method it throws TypeMismatchException. I think this could be happening because it is unable to assgin value to name instance variable. So there must be missing something in the users.hbm.xml file. So please help me.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 09, 2007 1:44 am 
Newbie

Joined: Thu Oct 04, 2007 5:00 am
Posts: 13
Hi I have solved the problem. The problem was with one-to-one tag used. In this tag I couldn't add column attribute which could help hibernate to know where is the column in the database?
So I used many-to-one like follow:
Users.hbm.xml
<hibernate-mapping>
<class name="hibernate.pojo.Users" table="USERS">
<id name="emailid" column="EMAILID" type="java.lang.String">
<generator class="assigned"/>
</id>

<!--unidirectional one-to-one mappings from User to Name-->
<many-to-one name="name" class="hibernate.pojo.Name" foreign-key="nameid" fetch="join" column="NAMEID"/>
</class>
</hibernate-mapping>

But, now it is not retriving data from Name table and assigning state to Name object (ie nameid, title,firstname,lastname).
So should I change the query "from hibernate.pojo.Users" to something else or there is still any problem in the Users.hbm.xml file.

Sandip Gaikwad.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 12, 2007 1:37 am 
Newbie

Joined: Thu Oct 04, 2007 5:00 am
Posts: 13
Hey please help. Please solve my problem.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 9 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.