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
|