-->
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.  [ 3 posts ] 
Author Message
 Post subject: Update to child column with foreign key makes no change?
PostPosted: Tue Jul 06, 2010 11:37 pm 
Newbie

Joined: Tue Apr 27, 2010 5:18 pm
Posts: 19
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.


Top
 Profile  
 
 Post subject: Re: Update to child column with foreign key makes no change?
PostPosted: Mon Jul 12, 2010 4:08 am 
Newbie

Joined: Tue Apr 27, 2010 5:18 pm
Posts: 19
bump.
I'm still lost and looking for help....


Top
 Profile  
 
 Post subject: Re: Update to child column with foreign key makes no change?
PostPosted: Sun Aug 08, 2010 11:31 am 
Newbie

Joined: Tue Apr 27, 2010 5:18 pm
Posts: 19
So I managed to find a solution to this problem....
It seems that Hibernate doesn't like having a foreign key, where some items are partially filled and others are empty...
here the SAP_PRUEFZIFFER was filled, as it was part of the PK, while the ATTACHMENT_LIST was NEVER filled, even though there was an entry in its referenced table for the SAP_PRUEFZIFFER + ATTACHMENT_LIST.

My solution was to create a second SAP_PRUEFZIFFER column for the foreign key entry.
This simple change was enough for Hibernate to fill all columns.

I plan to submit several test cases for the developers. Perhaps I've misunderstood something, but I think this is a bug. SQL (Oracle) has no problem with these tables....perhaps other Databases do have these issues.

Hopefully this helps anyone else looking for a solution to this problem.

Martin


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