-->
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.  [ 1 post ] 
Author Message
 Post subject: Issues setting up BLOB relationship
PostPosted: Mon Nov 21, 2005 6:42 am 
Newbie

Joined: Thu May 26, 2005 11:46 am
Posts: 4
Location: London UK
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version: 3.1rc2

Annotations: 3.1b6

Database: Oracle 9i

I'm trying to create Hibernate mappings for a legacy Oracle database. I'm almost there apart from one BLOB association which I can't get working. Perhaps someone on here might be able to explain what I'm doing wrong?

There are two tables as follows:
Code:
+----------+
|MESSAGE   |
|----------|
|id (PK)   |
|hash      |
|sender    |
|format    |
|status    |
+----------+

+-------------+
|MESSAGE_STORE|
|-------------|
|hash (PK)    |
|data (blob)  |
+-------------+


They are joined on the hash column and there is a referential integrity constraint on the hash column for MESSAGE_STORE.

Here are the POJOs I have defined:
Code:
@Entity
@Table(name = "RAWIN_MESSAGES")
class Message {
    private long id;

    @Id(generate = GeneratorType.NONE)
    @Column(name = "ID", unique = true, nullable = false)
    public long getId() {
        return this.id;
    }

    public void setId(long id) {
        this.id = id;
    }

    @OneToOne(cascade = CascadeType.ALL)
    @JoinColumn(name="HASH", unique = true, nullable = false)
    public MessageStore getMessageStore() {
        return this.MessageStore;
    }

    public void setMessageStore(MessageStore mssageStore) {
        this.messageStore = mssageStore;
    }   

    // ...other getters/setters
}


@Entity
@Table(name = "RAWIN_MESSAGE_STORE", uniqueConstraints = { @UniqueConstraint(columnNames = { "HASH" }) })
public class RawinMessageStore implements java.io.Serializable {

    private String hash;
    private SerializableBlob rawDataBlob = new SerializableBlob(new BlobImpl(new String("empty").getBytes()));

    @Id(generate = GeneratorType.NONE)
    @Column(name = "HASH", unique = true, nullable = false)
    public String getHash() {
        return this.hash;
    }

    public void setHash(String hash) {
        this.hash = hash;
    }

    @Column(name = "DATA", nullable = false)
    @Type(type = "java.sql.Blob")
    public SerializableBlob getRawDataBlob() {
        return rawDataBlob;
    }

    public void setRawDataBlob(SerializableBlob rawDataBlob) {
        this.rawDataBlob = rawDataBlob;
    }

    public void setRawData(InputStream data, int length) throws NoSuchAlgorithmException {
        DigestInputStream digestInputStream = new DigestInputStream(data, MessageDigest.getInstance("SHA1"));

        BlobImpl blobImpl = new BlobImpl(digestInputStream, length);
        setRawDataBlob(new SerializableBlob(blobImpl));
     
        hash = BASE64Encoder().encode(digestInputStream.getMessageDigest().digest());
}


I can successfully read data from the existing database but I get failures when I try to persist the data in the following manner:

Code:
    MessageStore messageStore = new MessageStore();
    InputStream is = new ByteArrayInputStream("THIS IS A TEST".getBytes());
    messageStore.setData(is, is.available());
    MessageStore result = messageStoreDao.makePersistent(messageStore);


(messageStoreDao is implemented using the GenericHibernateDAO pattern Christian recently blogged about: http://blog.hibernate.org/cgi-bin/blosx ... genericdao)

There error is:

ORA-02291: integrity constraint (SCHEMA.CONTRAINT_NAME) violated - parent key not found

I have tried various permutations of inserting Message object and MessageStore objects but I have a feeling it's the relationships I have set up in the above POJOs which is causing the problem.

Apologies if I'm missing something obvious. I have read the documentation several times, and checked the forums, but I can't find a reference to a similar issue.

Many thanks.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.