-->
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.  [ 2 posts ] 
Author Message
 Post subject: ClassCastException at org.hibernate.property.MapAccessor$Map
PostPosted: Tue Aug 25, 2009 10:09 am 
Newbie

Joined: Tue Aug 25, 2009 10:00 am
Posts: 2
Using hibernate distribution 3.3.2.GA (here's my config xml, mapping xml, POJO and save code)

<!DOCTYPE hibernate-configuration SYSTEM "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"[]>
<hibernate-configuration>
<session-factory>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost:3306/swift</property>
<property name="hibernate.connection.username">root</property>
<property name="connection.password"></property>
<!-- SQL dialect -->
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
<!-- Use the C3P0 connection pool provider -->
<property name="hibernate.c3p0.acquire_increment">1</property>
<property name="hibernate.c3p0.idle_test_period">100</property> <!-- seconds -->
<property name="hibernate.c3p0.max_size">100</property>
<property name="hibernate.c3p0.max_statements">0</property>
<property name="hibernate.c3p0.min_size">10</property>
<property name="hibernate.c3p0.timeout">100</property> <!-- seconds -->
<!-- Echo all executed SQL to stdout -->
<property name="show_sql">true</property>
<property name="hibernate.default_entity_mode">pojo</property>
<!-- List of mappings-->
<mapping resource="com/nnnn/swift/service/data/TypeValuePair.hbm.xml"/>
<mapping resource="com/nnnn/swift/service/data/DataParameterData.hbm.xml"/>
<mapping resource="com/nnnn/swift/service/data/DataParameterAttributesData.hbm.xml"/>
<mapping resource="com/nnnn/swift/service/data/SensorData.hbm.xml"/>
<mapping resource="com/nnnn/swift/service/data/CalculatedValue.hbm.xml"/>
<mapping resource="com/nnnn/swift/service/data/LocationData.hbm.xml"/>
<mapping resource="com/nnnn/swift/service/data/MagneticObservatoryNetworkData.hbm.xml"/>
<mapping resource="com/nnnn/swift/service/data/SatelliteData.hbm.xml"/>
<mapping resource="com/nnnn/swift/service/data/SpaceWxData.hbm.xml"/>
</session-factory>
</hibernate-configuration>

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping package="com.tdkc.swift.service.data" default-cascade="all">
<class entity-name="com.tdkc.swift.service.data.SpaceWxData">
<id name="id"
type="long"
column="spaceWxDataId">
<generator class="identity"/>
</id>
<!-- One-to-One with FK -->
<many-to-one name="Satellite"
class="com.tdkc.swift.service.data.SatelliteData"
column="satelliteId"
unique="true"
not-null="true"/>
<!-- One-to-One with FK -->
<many-to-one name="MagneticObservatoryNetwork"
class="com.tdkc.swift.service.data.MagneticObservatoryNetworkData"
column="magneticObservatoryNetworkId"
unique="true"
not-null="true"/>
</class>
</hibernate-mapping>

public class SpaceWxData implements IXMLSerialization {

private Long id;
private SatelliteData satellite = null;
private String msgGenDateTime = "";
private MagneticObservatoryNetworkData magObNetwork = null;

public SpaceWxData(){}

public Long getId() {
return id;
}

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

/**
* @return the msgGenDateTime
*/
public String getMsgGenDateTime() {
return msgGenDateTime;
}

/**
* @param msgGenDateTime the msgGenDateTime to set
*/
public void setMsgGenDateTime(String msgGenDateTime) {
this.msgGenDateTime = msgGenDateTime;
}

/**
* @return the satellite
*/
public SatelliteData getSatellite() {
return satellite;
}

/**
* @param satellite the satellite to set
*/
public void setSatellite(SatelliteData satellite) {
this.satellite = satellite;
}

/**
* @return the magObNetwork
*/
public MagneticObservatoryNetworkData getMagObNetwork() {
return magObNetwork;
}

/**
* @param magObNetwork the magObNetwork to set
*/
public void setMagObNetwork(MagneticObservatoryNetworkData magObNetwork) {
this.magObNetwork = magObNetwork;
}
}

private void saveSpaceWxData(SpaceWxData spaceWx) {
Session session = HibernateUtil.getSessionFactory().openSession();
session.beginTransaction();
Long generatedId = (Long) session.save(spaceWx);
session.getTransaction().commit();
}

When the save method is called, it throws the following error:
java.lang.ClassCastException: com.tdkc.swift.service.data.SpaceWxData
at org.hibernate.property.MapAccessor$MapGetter.get(MapAccessor.java:90)
at org.hibernate.tuple.entity.AbstractEntityTuplizer.getPropertyValue(AbstractEntityTuplizer.java:293)
at org.hibernate.persister.entity.AbstractEntityPersister.getPropertyValue(AbstractEntityPersister.java:3650)
at org.hibernate.engine.Cascade.cascade(Cascade.java:154)
at org.hibernate.event.def.AbstractSaveEventListener.cascadeBeforeSave(AbstractSaveEventListener.java:454)
at org.hibernate.event.def.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:288)
at org.hibernate.event.def.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:204)
at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:130)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:210)
at org.hibernate.event.def.DefaultSaveEventListener.saveWithGeneratedOrRequestedId(DefaultSaveEventListener.java:56)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:195)
at org.hibernate.event.def.DefaultSaveEventListener.performSaveOrUpdate(DefaultSaveEventListener.java:50)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:93)
at org.hibernate.impl.SessionImpl.fireSave(SessionImpl.java:566)
at org.hibernate.impl.SessionImpl.save(SessionImpl.java:554)
at org.hibernate.impl.SessionImpl.save(SessionImpl.java:550)
at com.nnnn.swift.service.persistence.SpaceWxStorage.saveSpaceWxData(SpaceWxStorage.java:39)

It seems that it's trying to cast my SpaceWxData object to a java.util.Map object when i debug the code.


Top
 Profile  
 
 Post subject: Re: ClassCastException at org.hibernate.property.MapAccessor$Map
PostPosted: Tue Aug 25, 2009 3:13 pm 
Newbie

Joined: Tue Aug 25, 2009 10:00 am
Posts: 2
I figured out my problem. Hibernate was using the wrong Tuplizer because I was missing the name attribute for the class mapping.

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping package="com.nnnn.swift.service.data" default-cascade="all">
<class entity-name="com.nnnn.swift.service.data.SpaceWxData"
name="com.nnnn.swift.service.data.SpaceWxData">
<id name="id"
type="long"
column="spaceWxDataId">
<generator class="identity"/>
</id>
<property name="msgGenDateTime"/>
<!-- One-to-One with FK -->
<many-to-one name="Satellite"
class="com.nnnn.swift.service.data.SatelliteData"
column="satellitePKId"
unique="true"
not-null="false"
cascade="all"/>
<!-- One-to-One with FK -->
<many-to-one name="MagObNetwork"
class="com.nnnn.swift.service.data.MagneticObservatoryNetworkData"
column="magneticObservatoryNetworkId"
unique="true"
not-null="false"
cascade="all"/>
</class>
</hibernate-mapping>


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.