Hi Hibernate users.
I've been staring at this problem for hours...I'm sure it some silly mistake on my part, but I'd appreciate any suggestions.
I have 4 tables, all of which have a relationship to one of these tables, "Attachment". Everything works fine, except for when I update Attachment, It never updates the value of ATTACHMENT_LIST_ID on the database :( I've removed a few of the more boring column definitions, to make it easier to understand the hbml.
I've only posted the hbml for the most relevant 2 tables. All other tables + columns seem to be working fine.
For the Attachment table
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated 06.07.2010 10:54:33 by Hibernate Tools 3.2.1.GA -->
<hibernate-mapping>
<class name="de.cs.anforderungsterminal.datatypes.Attachment" schema="BESTTERM" table="ATTACHMENT">
<composite-id class="de.cs.anforderungsterminal.datatypes.AttachmentId" name="id">
<key-property name="sapPruefziffer" type="string">
<column length="6" name="SAP_PRUEFZIFFER"/>
</key-property>
<key-property name="attachmentId" type="string">
<column length="20" name="ATTACHMENT_ID"/>
</key-property>
</composite-id>
<many-to-one class="de.cs.anforderungsterminal.datatypes.ArchivSystem" fetch="select" name="archivSystem">
<column length="6" name="ARCHIV_SYSTEM"/>
</many-to-one>
<many-to-one name="attachmentList" class="de.cs.anforderungsterminal.datatypes.AttachmentList" update="false" insert="false" fetch="select">
<column name="SAP_PRUEFZIFFER" length="6" not-null="true" />
<column name="ATTACHMENT_LIST_ID" length="20" />
</many-to-one>
...
<property name="mimeType" type="string">
<column name="MIME_TYPE"/>
</property>
<property name="filename" type="string">
<column name="FILENAME"/>
</property>
<property name="binaryFile" type="blob">
<column name="BINARY_FILE"/>
</property>
....
<set inverse="true" name="attachmentMetadatas">
<key>
<column length="6" name="SAP_PRUEFZIFFER" not-null="true"/>
<column length="20" name="ATTACHMENT_ID" not-null="true"/>
</key>
<one-to-many class="de.cs.anforderungsterminal.datatypes.AttachmentMetadata"/>
</set>
</class>
</hibernate-mapping>
ATTACHMENT_LIST_ID
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated 06.07.2010 10:54:33 by Hibernate Tools 3.2.1.GA -->
<hibernate-mapping>
<class name="de.cs.anforderungsterminal.datatypes.AttachmentList" schema="BESTTERM" table="ATTACHMENT_LIST">
<composite-id class="de.cs.anforderungsterminal.datatypes.AttachmentListId" name="id">
<key-property name="sapPruefziffer" type="string">
<column length="6" name="SAP_PRUEFZIFFER"/>
</key-property>
<key-property name="attachmentListId" type="string">
<column length="20" name="ATTACHMENT_LIST_ID"/>
</key-property>
</composite-id>
...
<set name="attachments" inverse="true">
<key>
<column name="SAP_PRUEFZIFFER" length="6" not-null="true" />
<column name="ATTACHMENT_LIST_ID" length="20" />
</key>
<one-to-many class="de.cs.anforderungsterminal.datatypes.Attachment" />
</set>
</class>
</hibernate-mapping>
SQL Attachment (Simplified)
Quote:
CREATE TABLE BESTTERM.ATTACHMENT
(
SAP_PRUEFZIFFER VARCHAR2(6),
ATTACHMENT_ID VARCHAR2(20),
ATTACHMENT_LIST_ID VARCHAR2(20),--optional parameter
MIME_TYPE VARCHAR2(255),
FILENAME NVARCHAR2(255),
BINARY_FILE BLOB,
ARCHIV_SYSTEM VARCHAR2(6),
...
CONSTRAINT FK_ATTACH_SAP_PRUEFZIFFER FOREIGN KEY (SAP_PRUEFZIFFER)
REFERENCES SAP_PRUEFZIFFER(SAP_PRUEFZIFFER) ON DELETE CASCADE,
CONSTRAINT FK_ATTACH_ARCHIV_SYSTEM FOREIGN KEY (ARCHIV_SYSTEM)
REFERENCES ARCHIV_SYSTEM(SYSTEM) ON DELETE CASCADE,
CONSTRAINT FK_ATTACH_LIST_ID FOREIGN KEY (SAP_PRUEFZIFFER, ATTACHMENT_LIST_ID)
REFERENCES ATTACHMENT_LIST(SAP_PRUEFZIFFER, ATTACHMENT_LIST_ID) ON DELETE CASCADE,
CONSTRAINT PK_ATTACHMENT PRIMARY KEY(SAP_PRUEFZIFFER,ATTACHMENT_ID)
) TABLESPACE USERS;
SQL AttachmentList (Simplified)
Quote:
CREATE TABLE BESTTERM.ATTACHMENT_LIST
(
SAP_PRUEFZIFFER VARCHAR2(6),
ATTACHMENT_LIST_ID VARCHAR2(20),
...
CONSTRAINT FK_ATTACH_LIST_SAP_PRUEFZIFFER FOREIGN KEY (SAP_PRUEFZIFFER)
REFERENCES SAP_PRUEFZIFFER(SAP_PRUEFZIFFER) ON DELETE CASCADE,
CONSTRAINT PK_ATTACHMENT_LIST PRIMARY KEY(SAP_PRUEFZIFFER, ATTACHMENT_LIST_ID)
) TABLESPACE USERS;
And here is my Unit Test. It produces no error messages, (as long as the ids are unique).
Code:
@Test
public void testSaveAttachment() throws Exception {
PersistanceSession session = instance;
PersistanceTransaction pt = session.beginTransaction();
AttachmentList list = session.getAttachmentList(new AttachmentListId("CSE100","27"));
AttachmentId id = new AttachmentId("CSE100","999999");
Attachment att= new Attachment(id, list);
list.getAttachments().add(att);
session.save(att);
session.update(list);
pt.commit();
}
In case your wondering.... I intentionaly don't close the session. I haven't figured out how to remove objects from the Hibernate....and JAXB/JAXWS needs to able to serialize my objects, so I keep 1 instance of my session. I don't get any errors and it updates/inserts any column EXCEPT for the reference to AttachmentList.
Any ideas on what could be causing this problem?
Thanks
Martin.