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.  [ 22 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: ClassCastException when calling flush()
PostPosted: Tue Jan 20, 2004 2:27 pm 
Beginner
Beginner

Joined: Mon Dec 01, 2003 8:48 pm
Posts: 47
Location: Texas, United States
Here's the stack trace...

java.lang.ClassCastException
[java] at net.sf.hibernate.type.LongType.set(LongType.java:28)
[java] at net.sf.hibernate.type.NullableType.nullSafeSet(NullableType.java:46)
[java] at net.sf.hibernate.type.NullableType.nullSafeSet(NullableType.java:31)
[java] at net.sf.hibernate.collection.CollectionPersister.writeIndex(CollectionPersister.ja
va:468)
[java] at net.sf.hibernate.collection.Map.writeTo(Map.java:189)
[java] at net.sf.hibernate.collection.CollectionPersister.recreate(CollectionPersister.java
:692)
[java] at net.sf.hibernate.impl.ScheduledCollectionRecreate.execute(ScheduledCollectionRecr
eate.java:23)
[java] at net.sf.hibernate.impl.SessionImpl.executeAll(SessionImpl.java:2101)
[java] at net.sf.hibernate.impl.SessionImpl.execute(SessionImpl.java:2077)
[java] at net.sf.hibernate.impl.SessionImpl.flush(SessionImpl.java:2017)

Here is my mapping file. I am using java.lang.Long for my id
<class name="CommonLogEvent" table="UL_COMMON_LOG_EVENT" dynamic-update="false" dynamic-insert="false">
<id name="id" column="cle_id" type="java.lang.Long">
<generator class="native"/>
</id>
<property name="observedTime" type="long" update="true" insert="true" column="observed_time" not-null="false"/>
<property name="version" type="java.lang.String" update="true" insert="true" column="version"/>
<property name="situation" type="java.lang.String" update="true" insert="true" column="situation"/>
<property name="message" type="java.lang.String" update="true" insert="true" column="message"/>
<property name="status" type="java.lang.String" update="true" insert="true" column="status"/>
<property name="severity" type="java.lang.String" update="true" insert="true" column="severity"/>
<property name="logLevel" type="int" update="true" insert="true" column="log_level"/>
<component name="componentIdentification">
<property name="addressType" type="java.lang.String" update="true" insert="true" column="address_type"/>
<property name="addressName" type="java.lang.String" update="true" insert="true" column="address_name"/>
<property name="componentName" type="java.lang.String" update="true" insert="true" column="component_name"/>
<property name="applicationName" type="java.lang.String" update="true" insert="true" column="application_name"/>
<property name="instanceName" type="java.lang.String" update="true" insert="true" column="instance_name"/>
<property name="threadName" type="java.lang.String" update="true" insert="true" column="thread_name"/>
<property name="environmentName" type="java.lang.String" update="true" insert="true" column="environment_name"/>
</component>
<map name="situationData" table="UL_SITUATION_DATA">
<key column="cle_id"/>
<index column="sd_id" type="java.lang.Long"/>
<element column="map_data" type="clob"/>
</map>
<map name="correlationData" table="UL_CORRELATION_DATA">
<key column="cle_id"/>
<index column="cd_id" type="java.lang.Long"/>
<element column="map_data" type="string"/>
</map>
<!--
To add non XDoclet property mappings, create a file named
hibernate-properties-Item.xml
containing the additional properties and place it in your merge dir.
-->
</class>



here is the method in my class

public void setId(Long id) {
this.id = id;
}

public Long getId() {
return id;
}

I don't understand why I am getting this error. Is it something to do with the observedTime attribute?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 20, 2004 5:53 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
tried just using type="long" ?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 20, 2004 6:09 pm 
Beginner
Beginner

Joined: Mon Dec 01, 2003 8:48 pm
Posts: 47
Location: Texas, United States
I just switched everything to long, and I got the same error. The Map's are causing the error somehow.

<class name="CommonLogEvent" table="UL_COMMON_LOG_EVENT" dynamic-update="false" dynamic-insert="false">
<id name="id" column="cle_id" type="long"> <generator class="native"/>
</id>
...bunch of props not shown...
<map name="situationData" table="UL_SITUATION_DATA">
<key column="cle_id"/>
<index column="sd_id" type="long"/>
<element column="map_data" type="clob"/>
</map>
<map name="correlationData" table="UL_CORRELATION_DATA">
<key column="cle_id"/>
<index column="cd_id" type="long"/>
<element column="map_data" type="string"/>
</map>


at net.sf.hibernate.type.LongType.set(LongType.java:28)
at net.sf.hibernate.type.NullableType.nullSafeSet(NullableType.java:46)
at net.sf.hibernate.type.NullableType.nullSafeSet(NullableType.java:31)
at net.sf.hibernate.collection.CollectionPersister.writeIndex(CollectionPersister.java:468)
at net.sf.hibernate.collection.Map.writeTo(Map.java:189)


When I remove the Map mappings, I don't get an error, however nothings gets persisted to the database.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 20, 2004 6:13 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
Which Hibernate version are you using?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 20, 2004 6:14 pm 
Beginner
Beginner

Joined: Mon Dec 01, 2003 8:48 pm
Posts: 47
Location: Texas, United States
I am using hibernate-2.0.1.jar.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 20, 2004 6:15 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
Try using a recent version


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 20, 2004 6:38 pm 
Beginner
Beginner

Joined: Mon Dec 01, 2003 8:48 pm
Posts: 47
Location: Texas, United States
Ok, I am now using the hibernate2.jar. I am referencing every jar and zip file in the lib directory like so:
<fileset dir="C:\lib">
<include name="**/*.jar"/>
<include name="**/*.zip"/>
</fileset>

I got the following error"
[java] 1) testSaveCommonLogEvent(HibernateDatastoreTE
ST)java.lang.IllegalAccessError
[java] at net.sf.cglib.core.ClassEmitter.setTarget(ClassEmitter.java:87)
[java] at net.sf.cglib.core.ClassEmitter.<init>(ClassEmitter.java:79)
[java] at net.sf.cglib.reflect.FastClassEmitter.<init>(FastClassEmitter.java:91)
[java] at net.sf.cglib.reflect.FastClass$Generator.generateClass(FastClass.java:100)
[java] at net.sf.cglib.core.DefaultGeneratorStrategy.generate(DefaultGeneratorStrategy.java
:63)
[java] at net.sf.cglib.core.AbstractClassGenerator.create(AbstractClassGenerator.java:190)
[java] at net.sf.cglib.reflect.FastClass$Generator.create(FastClass.java:92)
[java] at net.sf.cglib.reflect.FastClass.create(FastClass.java:74)
[java] at net.sf.hibernate.type.ComponentType.<init>(ComponentType.java:113)
[java] at net.sf.hibernate.cfg.Binder.bindComponent(Binder.java:871)
[java] at net.sf.hibernate.cfg.Binder.propertiesFromXML(Binder.java:1013)
[java] at net.sf.hibernate.cfg.Binder.bindRootClass(Binder.java:344)
[java] at net.sf.hibernate.cfg.Binder.bindRoot(Binder.java:1204)
[java] at net.sf.hibernate.cfg.Configuration.add(Configuration.java:247)
[java] at net.sf.hibernate.cfg.Configuration.addInputStream(Configuration.java:281)
[java] at net.sf.hibernate.cfg.Configuration.addClass(Configuration.java:322)
HibernateDatastore.<init>(HibernateData
store.java:26)
testSaveCommonLo
gEvent(HibernateDatastoreTEST.java:43)
[java] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[java] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
[java] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 20, 2004 6:42 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
Remove old cglib.jar : http://www.hibernate.org/74.html#A4


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 20, 2004 6:54 pm 
Beginner
Beginner

Joined: Mon Dec 01, 2003 8:48 pm
Posts: 47
Location: Texas, United States
Ok, thanks for the link. I fixed that problem, and now I have the original error again.

[java] .Hibernate: select hibernate_sequence.nextval from dual
[java] Hibernate: insert into UL_COMMON_LOG_EVENT (observed_time, version, situation, message,
status, severity, log_level, address_type, address_name, component_name, application_name, instance_
name, thread_name, environment_name, cle_id) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
[java] Hibernate: insert into UL_SITUATION_DATA (cle_id, sd_id, map_data) values (?, ?, ?)
[java] E
[java] Time: 2.333
[java] There was 1 error:
[java] 1) testSaveCommonLogEvent(HibernateDatastoreTEST)java.lang.ClassCastException [java] at net.sf.hibernate.type.LongType.set(LongType.java:32)
[java] at net.sf.hibernate.type.NullableType.nullSafeSet(NullableType.java:48)
[java] at net.sf.hibernate.type.NullableType.nullSafeSet(NullableType.java:35)
[java] at net.sf.hibernate.collection.AbstractCollectionPersister.writeIndex(AbstractCollec
tionPersister.java:394)
[java] at net.sf.hibernate.collection.Map.writeTo(Map.java:195)
[java] at net.sf.hibernate.collection.AbstractCollectionPersister.recreate(AbstractCollecti
onPersister.java:537)
[java] at net.sf.hibernate.impl.ScheduledCollectionRecreate.execute(ScheduledCollectionRecr
eate.java:23)
[java] at net.sf.hibernate.impl.SessionImpl.executeAll(SessionImpl.java:2308)
[java] at net.sf.hibernate.impl.SessionImpl.execute(SessionImpl.java:2265)
[java] at net.sf.hibernate.impl.SessionImpl.flush(SessionImpl.java:2187)
[java] at HibernateDatastore.save(HibernateDatast
ore.java:47)
[java] at HibernateDatastoreTEST.testSaveCommonLo
gEvent(HibernateDatastoreTEST.java:44)
[java] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[java] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
[java] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java
:25)
[java] at HibernateDatastoreTEST.main(HibernateDa
tastoreTEST.java:48)


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 20, 2004 7:28 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
What happens if you remove just the type attribute of the index element?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 20, 2004 7:36 pm 
Beginner
Beginner

Joined: Mon Dec 01, 2003 8:48 pm
Posts: 47
Location: Texas, United States
It complians that the index type is required...

[java] Jan 20, 2004 4:34:34 PM net.sf.hibernate.cfg.Configuration secondPassCompile
[java] INFO: processing one-to-many association mappings [java] net.sf.hibernate.MappingException: map index element must specify a type [java] at net.sf.hibernate.cfg.Binder.bindMapSecondPass(Binder.java:1102)
[java] at net.sf.hibernate.cfg.Binder$MapSecondPass.secondPass(Binder.java:1347)
[java] at net.sf.hibernate.cfg.Binder$SecondPass.doSecondPass(Binder.java:1303)
[java] at net.sf.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:589)
[java] at net.sf.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:732)


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 20, 2004 7:43 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
Okay, yes - are you sure you are really using java.lang.Long as the map key objects?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 20, 2004 7:50 pm 
Beginner
Beginner

Joined: Mon Dec 01, 2003 8:48 pm
Posts: 47
Location: Texas, United States
That's it!! I did not make the connection that the Map key data type needs to match the column data type. I don't know what I was thinking...

Anyway, I got this output...

[java] .Hibernate: select hibernate_sequence.nextval from dual
[java] Hibernate: insert into UL_COMMON_LOG_EVENT (observed_time, version, situation, message,
status, severity, log_level, address_type, address_name, component_name, application_name, instance_
name, thread_name, environment_name, cle_id) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
[java] Hibernate: insert into UL_SITUATION_DATA (cle_id, sd_id, map_data) values (?, ?, ?)
[java] Hibernate: insert into UL_CORRELATION_DATA (cle_id, cd_id, map_data) values (?, ?, ?)

[java] Time: 2.324

[java] OK (1 test)

However, nothing was persisted to the database. Here is the code snippet for my implementation...
public void save(CommonLogEvent cle) {
Session session = null;
try {
session = sessionFactory.openSession();
session.save(cle);
session.flush();
} catch (HibernateException ex) {
ex.printStackTrace();
//handle exception
} finally {
close(session);
}
}

private void close(Session session) {
if (session != null) {
try {
session.close();
} catch (Exception ex) {
ex.printStackTrace();
//@TODO: handle exception
}
}
}

What could cause the data not to appear? Could this be a commit issue? I thought JDBC was auto-commit by default.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 20, 2004 7:52 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
Please wrap it in a hibernate transaction to be sure.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 20, 2004 7:59 pm 
Beginner
Beginner

Joined: Mon Dec 01, 2003 8:48 pm
Posts: 47
Location: Texas, United States
YES!!!! My first persisted object!! Thanks to you! I really appreciate your time, you are very kind.

I will be calling Hibernate though a stateless sesion bean, using transaction in the container. WIll these transactions not play well with Hibernate's transactions?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 22 posts ]  Go to page 1, 2  Next

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.