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.
|