-->
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.  [ 4 posts ] 
Author Message
 Post subject: Changing type of persisted entity?
PostPosted: Mon Nov 08, 2004 1:36 am 
Newbie

Joined: Wed Jul 07, 2004 11:49 am
Posts: 6
Hoping for a bit of design help here. This is what I have:

class File; // info about a file, including its location on disk

class ImageFile extends File; // adds info on format, size etc

some memory holding the contents of a nameless file.

This is what I want to do

1) Construct a File and persist it in order to get a unique ID
2) Write out a corresponding on file on disk with the database ID in its name, dumping the contents from memory
3) Check whether the file is a recognized image format (using external program -- this is why it needs to be dumped to disk first)
4) Re-set Hibernate/DB entry to ImageFile type if necessary

My question is, is this possible to do safely in Hibernate, using joined-subclass or discriminators?

I can think of various workarounds involving either

1) writing out a temp file, testing it, constructing a File or ImageFile as appropriate, persisting it, and renaming the file, or
2) not using inheritance, rather just have a possibly null field in File pointing to another entity with image related info (a kind of faked joined-subclass)

but both of these are rather clumsy. I'm hoping some more experienced Hibernate users can help me with something more elegant.

thanks


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 08, 2004 4:35 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
This is the same problem as "can my object change its Class Type during its lifetime", which is not possible of course. This has been extensively discussed in the forum already in an older thread. I'd suggest you redesing your class model.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 08, 2004 6:55 am 
Newbie

Joined: Wed Jul 07, 2004 11:49 am
Posts: 6
Great, thanks for the quick reply. I'll try searching again.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 25, 2004 12:30 pm 
Beginner
Beginner

Joined: Sun Feb 08, 2004 4:09 pm
Posts: 46
This definitly should be supported. Of course, only for changing types walking up and down in the same hierachy....


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