I don't know about sample code (that would take some time that I don't have) but I can offer some suggestions...
The main issue is: how much do you know about the Excell file?
If it's a single worksheet with a straighforward table of data where you know each column's format completely, then no problem. Just export the spreadsheet to CSV, create a POJO with getter/setter methods for each column in the table and give it a readFromCSVLine(String csv) method. Then call session.save(obj); Job done. For simple, known objects it could be coded up in about half an hour.
At this point I have to ask wether it's actually worth using hibernate for this, or if you could just insert records into the database directly. Same effect, cut out the pointless pojo. If the pojo is to have some other functionality as well (maybe data validation at a minimum?) then use it, otherwise it's a bit pointless.
There is also a feature of hibernate for dynamic objects - I believe this basically means manipulating name/value pairs directly - but I have never used this feature so perhaps someone else could comment.
If it's format is not known then this is a much bigger project. You must be dynamically loading the hibernate mappings for your unknown objects and having some method of tieing in one are of the spreadsheet (probably a whole sheet) with a particular class type. Then you'd need to do come cleverness - either have each pojo inherit from a base class with your readFromExcellRange(Range...) or get creative with reflection.
I hope this helps.
Regards,
Ben.
|