Hello people, this problem has been driving me absolutely crazy. I am trying to do a simple one-to-many mapping from an array (also tried it as a set). I've gotten various errors.... I've read the docs so many times I think my head is about to explode. The odd thing is, I have another similar case which works just fine.
This version has no errors, but the parent_id is never updated in the associated class...
Hibernate version:
2.1.6
Mapping documents:
<class name="REProperties" table="Rets_Properties">
<id name="id"><generator class="native"/></id>
<property name="copyrightNotice" column="copyright" type="string"/>
<property name="disclaimer" column="disclaimer" type="string"/>
<array name="residentialProperty" cascade="all">
<key column="RETS_PARENT_ID"/>
<index column="rets_idx"/>
<one-to-many class="ResidentialProperty"/>
</array>
</class>
<class name="ResidentialProperty" table="Property">
<id name="id" column="pro_property_id">
<generator class="sequence">
<param name="sequence">SEQ_PROPERTY</param>
</generator>
</id>
<component name="bedrooms" class="IntAttr">
<property name="valAsInt" type="int" column="pro_bedrooms"/>
</component>
<component name="baths" class="Baths">
<component name="bathsFull" class="IntAttr">
<property name="valAsInt" type="int" column="pro_bath_full"/>
</component>
<component name="bathsHalf" class="IntAttr">
<property name="valAsInt" type="int" column="pro_bath_half"/>
</component>
<component name="bathsThreeQuarter" class="IntAttr">
<property name="valAsInt" type="int" column="pro_bath_3qtr"/>
</component>
</component>
<component name="livingArea" class="LivingArea">
<component name="area" class="Area">
<property name="areaAsInt" type="int" column="PRO_SQ_FT"/>
</component>
</component>
<component name="lotSize" class="LotSize">
<property name="lotSize" column="PRO_LOT_SIZE"/>
</component>
<component name="stories" class="FloatOrInteger">
<property name="valAsFloat" column="PRO_STORIES"/>
</component>
<component name="yearBuilt" class="YearBuilt">
<property name="yearAsInt" column="pro_year_built" type="int"/>
</component>
<component name="rooms" class="Rooms">
<component name="totalRooms" class="IntAttr">
<property name="valAsInt" column="pro_total_rooms"/>
</component>
</component>
<array name="theRooms" cascade="all" inverse="true">
<key column="PRO_PROPERTY_ID"/>
<index column="ROD_SEQUENCE"/>
<one-to-many class="RoomData"/>
</array>
</class>
<class name="RoomData" table="ROOM_DIM">
<id name="id" column="ROD_ROOM_DIM" unsaved-value="null">
<generator class="sequence">
<param name="sequence">SEQ_ROOM_DIM</param>
</generator>
</id>
<many-to-one class="ResidentialProperty" column="PRO_PROPERTY_ID" name="parent"/>
<property name="roomtype" column="ROD_ROOM_NAME"/>
<property name="length" column="ROD_LENGTH"/>
<property name="width" column="ROD_WIDTH"/>
</class>
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close():
Session session = HibernateUtil.currentSession();
Transaction tx = null;
try {
tx = session.beginTransaction();
session.saveOrUpdate(result);
session.flush();
tx.commit();
}
catch (Exception e) {
if (tx!=null) tx.rollback();
throw e;
}
finally {
HibernateUtil.closeSession();
}
Full stack trace of any exception that occurs:
Currently, none.
Name and version of the database you are using:
Oracle 9
Debug level Hibernate log excerpt:
2005-01-07 12:55:28,234 DEBUG (EntityPersister.java:453) - Inserting entity: [com.coldwellbanker.rets.genclasses.RoomData#22245579]
2005-01-07 12:55:28,234 DEBUG (BatcherImpl.java:196) - about to open: 0 open PreparedStatements, 0 open ResultSets
2005-01-07 12:55:28,234 DEBUG (BatcherImpl.java:237) - insert into ROOM_DIM (PRO_PROPERTY_ID, ROD_ROOM_NAME, ROD_LENGTH, ROD_WIDTH, ROD_ROOM_DIM) values (?, ?, ?, ?, ?)
Hibernate: insert into ROOM_DIM (PRO_PROPERTY_ID, ROD_ROOM_NAME, ROD_LENGTH, ROD_WIDTH, ROD_ROOM_DIM) values (?, ?, ?, ?, ?)
2005-01-07 12:55:28,234 DEBUG (BatcherImpl.java:241) - preparing statement
2005-01-07 12:55:28,234 DEBUG (EntityPersister.java:388) - Dehydrating entity: [com.coldwellbanker.rets.genclasses.RoomData#22245579]
2005-01-07 12:55:28,234 DEBUG (NullableType.java:41) - binding null to parameter: 1
2005-01-07 12:55:28,234 DEBUG (NullableType.java:46) - binding 'Dining Room' to parameter: 2
2005-01-07 12:55:28,234 DEBUG (NullableType.java:46) - binding '10.0' to parameter: 3
2005-01-07 12:55:28,234 DEBUG (NullableType.java:46) - binding '11.0' to parameter: 4
2005-01-07 12:55:28,234 DEBUG (NullableType.java:46) - binding '22245579' to parameter: 5
2005-01-07 12:55:28,234 DEBUG (BatchingBatcher.java:28) - Adding to batch
2005-01-07 12:55:28,250 DEBUG (EntityPersister.java:453) - Inserting entity: [com.coldwellbanker.rets.genclasses.RoomData#22245580]
2005-01-07 12:55:28,250 DEBUG (EntityPersister.java:388) - Dehydrating entity: [com.coldwellbanker.rets.genclasses.RoomData#22245580]
2005-01-07 12:55:28,250 DEBUG (NullableType.java:41) - binding null to parameter: 1
2005-01-07 12:55:28,250 DEBUG (NullableType.java:46) - binding 'Basement' to parameter: 2
2005-01-07 12:55:28,250 DEBUG (NullableType.java:46) - binding '40.0' to parameter: 3
2005-01-07 12:55:28,250 DEBUG (NullableType.java:46) - binding '30.0' to parameter: 4
2005-01-07 12:55:28,250 DEBUG (NullableType.java:46) - binding '22245580' to parameter: 5
2005-01-07 12:55:28,250 DEBUG (BatchingBatcher.java:28) - Adding to batch
2005-01-07 12:55:28,250 DEBUG (EntityPersister.java:453) - Inserting entity: [com.coldwellbanker.rets.genclasses.RoomData#22245581]
2005-01-07 12:55:28,250 DEBUG (EntityPersister.java:388) - Dehydrating entity: [com.coldwellbanker.rets.genclasses.RoomData#22245581]
2005-01-07 12:55:28,250 DEBUG (NullableType.java:41) - binding null to parameter: 1
2005-01-07 12:55:28,250 DEBUG (NullableType.java:46) - binding 'Family Room' to parameter: 2
2005-01-07 12:55:28,250 DEBUG (NullableType.java:46) - binding '10.0' to parameter: 3
2005-01-07 12:55:28,250 DEBUG (NullableType.java:46) - binding '20.0' to parameter: 4
2005-01-07 12:55:28,250 DEBUG (NullableType.java:46) - binding '22245581' to parameter: 5
2005-01-07 12:55:28,250 DEBUG (BatchingBatcher.java:28) - Adding to batch
2005-01-07 12:55:28,250 DEBUG (EntityPersister.java:453) - Inserting entity: [com.coldwellbanker.rets.genclasses.RoomData#22245582]
2005-01-07 12:55:28,250 DEBUG (EntityPersister.java:388) - Dehydrating entity: [com.coldwellbanker.rets.genclasses.RoomData#22245582]
2005-01-07 12:55:28,250 DEBUG (NullableType.java:41) - binding null to parameter: 1
2005-01-07 12:55:28,250 DEBUG (NullableType.java:46) - binding 'Living Room' to parameter: 2
2005-01-07 12:55:28,250 DEBUG (NullableType.java:46) - binding '14.0' to parameter: 3
2005-01-07 12:55:28,250 DEBUG (NullableType.java:46) - binding '10.0' to parameter: 4
2005-01-07 12:55:28,250 DEBUG (NullableType.java:46) - binding '22245582' to parameter: 5
2005-01-07 12:55:28,250 DEBUG (BatchingBatcher.java:28) - Adding to batch
2005-01-07 12:55:28,250 DEBUG (BatchingBatcher.java:50) - Executing batch size: 4
2005-01-07 12:55:28,250 DEBUG (BatchingBatcher.java:58) - success of batch update unknown: 0
2005-01-07 12:55:28,250 DEBUG (BatchingBatcher.java:58) - success of batch update unknown: 1
2005-01-07 12:55:28,250 DEBUG (BatchingBatcher.java:58) - success of batch update unknown: 2
2005-01-07 12:55:28,265 DEBUG (BatchingBatcher.java:58) - success of batch update unknown: 3
2005-01-07 12:55:28,265 DEBUG (BatcherImpl.java:203) - done closing: 0 open PreparedStatements, 0 open ResultSets
2005-01-07 12:55:28,265 DEBUG (BatcherImpl.java:261) - closing statement
2005-01-07 12:55:28,265 DEBUG (EntityPersister.java:646) - Updating entity: [com.coldwellbanker.rets.genclasses.ResidentialProperty#89]
2005-01-07 12:55:28,265 DEBUG (BatcherImpl.java:196) - about to open: 0 open PreparedStatements, 0 open ResultSets
2005-01-07 12:55:28,265 DEBUG (BatcherImpl.java:237) - update Property set pro_bedrooms=?, pro_bath_full=?, pro_bath_half=?, pro_bath_3qtr=?, PRO_SQ_FT=?, PRO_LOT_SIZE=?, PRO_STORIES=?, pro_year_built=?, pro_total_rooms=? where pro_property_id=?
Hibernate: update Property set pro_bedrooms=?, pro_bath_full=?, pro_bath_half=?, pro_bath_3qtr=?, PRO_SQ_FT=?, PRO_LOT_SIZE=?, PRO_STORIES=?, pro_year_built=?, pro_total_rooms=? where pro_property_id=?
2005-01-07 12:55:28,265 DEBUG (BatcherImpl.java:241) - preparing statement
2005-01-07 12:55:28,265 DEBUG (EntityPersister.java:388) - Dehydrating entity: [com.coldwellbanker.rets.genclasses.ResidentialProperty#89]
2005-01-07 12:55:28,265 DEBUG (NullableType.java:46) - binding '6' to parameter: 1
2005-01-07 12:55:28,265 DEBUG (NullableType.java:46) - binding '3' to parameter: 2
2005-01-07 12:55:28,265 DEBUG (NullableType.java:46) - binding '1' to parameter: 3
2005-01-07 12:55:28,265 DEBUG (NullableType.java:41) - binding null to parameter: 4
2005-01-07 12:55:28,265 DEBUG (NullableType.java:46) - binding '3000' to parameter: 5
2005-01-07 12:55:28,265 DEBUG (NullableType.java:46) - binding '10 Acres' to parameter: 6
2005-01-07 12:55:28,265 DEBUG (NullableType.java:46) - binding '3.0' to parameter: 7
2005-01-07 12:55:28,265 DEBUG (NullableType.java:46) - binding '2001' to parameter: 8
2005-01-07 12:55:28,265 DEBUG (NullableType.java:46) - binding '10' to parameter: 9
2005-01-07 12:55:28,265 DEBUG (NullableType.java:46) - binding '89' to parameter: 10
2005-01-07 12:55:28,265 DEBUG (BatchingBatcher.java:28) - Adding to batch
2005-01-07 12:55:28,265 DEBUG (BatchingBatcher.java:50) - Executing batch size: 1
2005-01-07 12:55:28,265 DEBUG (BatchingBatcher.java:58) - success of batch update unknown: 0
2005-01-07 12:55:28,265 DEBUG (BatcherImpl.java:203) - done closing: 0 open PreparedStatements, 0 open ResultSets
2005-01-07 12:55:28,265 DEBUG (BatcherImpl.java:261) - closing statement
2005-01-07 12:55:28,265 DEBUG (AbstractCollectionPersister.java:953) - Deleting collection: [com.coldwellbanker.rets.genclasses.RETS.REData#5000383]
2005-01-07 12:55:28,265 DEBUG (BatcherImpl.java:196) - about to open: 0 open PreparedStatements, 0 open ResultSets
2005-01-07 12:55:28,265 DEBUG (BatcherImpl.java:237) - update Rets_Data set parent_id=null, idx=null where parent_id=?
Hibernate: update Rets_Data set parent_id=null, idx=null where parent_id=?
2005-01-07 12:55:28,265 DEBUG (BatcherImpl.java:241) - preparing statement
2005-01-07 12:55:28,265 DEBUG (NullableType.java:46) - binding '5000383' to parameter: 1
2005-01-07 12:55:28,265 DEBUG (BatchingBatcher.java:28) - Adding to batch
2005-01-07 12:55:28,265 DEBUG (AbstractCollectionPersister.java:985) - done deleting collection
2005-01-07 12:55:28,265 DEBUG (AbstractCollectionPersister.java:953) - Deleting collection: [com.coldwellbanker.rets.genclasses.REProperties.residentialProperty#5000385]
2005-01-07 12:55:28,265 DEBUG (BatchingBatcher.java:50) - Executing batch size: 1
2005-01-07 12:55:28,281 DEBUG (BatchingBatcher.java:58) - success of batch update unknown: 0
2005-01-07 12:55:28,281 DEBUG (BatcherImpl.java:203) - done closing: 0 open PreparedStatements, 0 open ResultSets
2005-01-07 12:55:28,281 DEBUG (BatcherImpl.java:261) - closing statement
2005-01-07 12:55:28,281 DEBUG (BatcherImpl.java:196) - about to open: 0 open PreparedStatements, 0 open ResultSets
2005-01-07 12:55:28,281 DEBUG (BatcherImpl.java:237) - update Property set RETS_PARENT_ID=null, rets_idx=null where RETS_PARENT_ID=?
Hibernate: update Property set RETS_PARENT_ID=null, rets_idx=null where RETS_PARENT_ID=?
2005-01-07 12:55:28,281 DEBUG (BatcherImpl.java:241) - preparing statement
2005-01-07 12:55:28,281 DEBUG (NullableType.java:46) - binding '5000385' to parameter: 1
2005-01-07 12:55:28,281 DEBUG (BatchingBatcher.java:28) - Adding to batch
2005-01-07 12:55:28,281 DEBUG (AbstractCollectionPersister.java:985) - done deleting collection
2005-01-07 12:55:28,281 DEBUG (BatchingBatcher.java:50) - Executing batch size: 1
2005-01-07 12:55:28,921 DEBUG (BatchingBatcher.java:58) - success of batch update unknown: 0
2005-01-07 12:55:28,921 DEBUG (BatcherImpl.java:203) - done closing: 0 open PreparedStatements, 0 open ResultSets
2005-01-07 12:55:28,921 DEBUG (BatcherImpl.java:261) - closing statement
2005-01-07 12:55:28,921 DEBUG (AbstractCollectionPersister.java:1015) - Inserting collection: [com.coldwellbanker.rets.genclasses.RETS.REData#5000383]
2005-01-07 12:55:28,921 DEBUG (BatcherImpl.java:196) - about to open: 0 open PreparedStatements, 0 open ResultSets
2005-01-07 12:55:28,921 DEBUG (BatcherImpl.java:237) - update Rets_Data set parent_id=?, idx=? where id=?
Hibernate: update Rets_Data set parent_id=?, idx=? where id=?
2005-01-07 12:55:28,921 DEBUG (BatcherImpl.java:241) - preparing statement
2005-01-07 12:55:28,921 DEBUG (NullableType.java:46) - binding '5000383' to parameter: 1
2005-01-07 12:55:28,921 DEBUG (NullableType.java:46) - binding '5000384' to parameter: 3
2005-01-07 12:55:28,921 DEBUG (NullableType.java:46) - binding '0' to parameter: 2
2005-01-07 12:55:28,921 DEBUG (BatchingBatcher.java:28) - Adding to batch
2005-01-07 12:55:28,921 DEBUG (AbstractCollectionPersister.java:1059) - done inserting collection: 1 rows inserted
2005-01-07 12:55:28,921 DEBUG (AbstractCollectionPersister.java:1015) - Inserting collection: [com.coldwellbanker.rets.genclasses.REProperties.residentialProperty#5000385]
2005-01-07 12:55:28,921 DEBUG (BatchingBatcher.java:50) - Executing batch size: 1
2005-01-07 12:55:28,921 DEBUG (BatchingBatcher.java:58) - success of batch update unknown: 0
2005-01-07 12:55:28,921 DEBUG (BatcherImpl.java:203) - done closing: 0 open PreparedStatements, 0 open ResultSets
2005-01-07 12:55:28,921 DEBUG (BatcherImpl.java:261) - closing statement
2005-01-07 12:55:28,921 DEBUG (BatcherImpl.java:196) - about to open: 0 open PreparedStatements, 0 open ResultSets
2005-01-07 12:55:28,937 DEBUG (BatcherImpl.java:237) - update Property set RETS_PARENT_ID=?, rets_idx=? where pro_property_id=?
Hibernate: update Property set RETS_PARENT_ID=?, rets_idx=? where pro_property_id=?
2005-01-07 12:55:28,937 DEBUG (BatcherImpl.java:241) - preparing statement
2005-01-07 12:55:28,937 DEBUG (NullableType.java:46) - binding '5000385' to parameter: 1
2005-01-07 12:55:28,937 DEBUG (NullableType.java:46) - binding '89' to parameter: 3
2005-01-07 12:55:28,937 DEBUG (NullableType.java:46) - binding '0' to parameter: 2
2005-01-07 12:55:28,937 DEBUG (BatchingBatcher.java:28) - Adding to batch
2005-01-07 12:55:28,937 DEBUG (AbstractCollectionPersister.java:1059) - done inserting collection: 1 rows inserted
2005-01-07 12:55:28,937 DEBUG (BatchingBatcher.java:50) - Executing batch size: 1
2005-01-07 12:55:28,937 DEBUG (BatchingBatcher.java:58) - success of batch update unknown: 0
2005-01-07 12:55:28,937 DEBUG (BatcherImpl.java:203) - done closing: 0 open PreparedStatements, 0 open ResultSets
2005-01-07 12:55:28,937 DEBUG (BatcherImpl.java:261) - closing statement
2005-01-07 12:55:28,937 DEBUG (SessionImpl.java:2815) - post flush
2005-01-07 12:55:28,937 DEBUG (SessionImpl.java:572) - transaction completion
2005-01-07 12:55:28,937 DEBUG (SessionImpl.java:560) - closing session
2005-01-07 12:55:28,937 DEBUG (SessionImpl.java:3327) - disconnecting session
2005-01-07 12:55:28,937 DEBUG (DriverManagerConnectionProvider.java:120) - returning connection to pool, pool size: 1
2005-01-07 12:55:28,937 DEBUG (SessionImpl.java:572) - transaction completion
As I said, this inserts the records, but it never updates the PRO_PROPERTY_ID field in the database. I've tried adding not-null to the mapping for the many-to-one reverse mapping and that gives an error about setting a null value. I've also tried explicitly setting the parent value iin the RoomData class and that complains about no persister for java.lang.Long....
here is the java code for the RoomData class:
Code:
/**
* Created on Jan 6, 2005
* $Log$
*
*/
package com.coldwellbanker.rets.genclasses;
import com.coldwellbanker.rets.data.DataObject;
/**
* @author rmangi
*
* TODO To change the template for this generated type comment go to
* Window - Preferences - Java - Code Style - Code Templates
*/
public class RoomData {
/**
public static final int LIVING_ROOM = 1;
public static final int DINING_ROOM = 2;
public static final int DEN = 3;
public static final int EAT_IN_KITCHEN = 4;
public static final int FAMILY_ROOM = 5;
public static final int GREAT_ROOM = 6;
public static final int LIBRARY = 7;
public static final int LIVING_DINING_ROOM = 8;
public static final int SCREEN_ROOM = 9;
public static final int WORKSHOP = 10;
public static final int BREAKFAST_ROOM = 11;
public static final int BEDROOM1 = 12;
public static final int BEDROOM2 = 13;
public static final int BEDROOM3 = 14;
public static final int MASTER_BEDROOM = 15;
public static final int MEDIA_ROOM = 16;
public static final int BASEMENT = 17;
*/
String roomtype;
String length;
String width;
Long parent;
Long id;
public RoomData() {}
/**
* @param roomtype
* @param length
* @param width
*/
public RoomData(String roomtype, Float length, Float width, Long parentId) {
this.roomtype = roomtype;
this.length = length.toString();
this.width = width.toString();
this.parent = parentId;
}
/**
* @return Returns the id.
*/
public Long getId() {
return id;
}
/**
* @param id The id to set.
*/
public void setId(Long id) {
this.id = id;
}
/**
* @return Returns the parent.
*/
public Long getParent() {
return parent;
}
/**
* @param parent The parent to set.
*/
public void setParent(Long parent) {
System.out.println("Parentid:"+parent);
this.parent = parent;
}
/**
* @return Returns the length.
*/
public String getLength() {
return length;
}
/**
* @param length The length to set.
*/
public void setLength(String length) {
this.length = length;
}
/**
* @return Returns the roomtype.
*/
public String getRoomtype() {
return roomtype;
}
/**
* @param roomtype The roomtype to set.
*/
public void setRoomtype(String roomtype) {
this.roomtype = roomtype;
}
/**
* @return Returns the width.
*/
public String getWidth() {
return width;
}
/**
* @param width The width to set.
*/
public void setWidth(String width) {
this.width = width;
}
}
[/list]