2

I have a java class to store Media objects for a movie/TV/DVD index. I'm planning to try to store these objects in a JavaDB database. It will have many thousands of entries.

I have read about serializing objects, and also a bit about hibernate and the persistence API, although I don't really understand how they work. I'm just getting confused on what exactly I should be learning how to do. Should I worry about these, or instead just make a table with all the info in VARCHAR columns?

Can anyone give me any tips on what system they would use to store all this info into a database? Or maybe just some general pointers on what you would do, and why?

Obviously I'm a newbie with databases. I have just done this codejava tutorial and can successfully create/connect to a JavaDB database.

Thanks!

public class Media {

    File file_location;
    String filename;
    Date date;
    int hres;
    int vres;
    boolean has_tbn;
    File tbnloc;
    boolean has_ss;
    File ssloc;
    int length;
    String[] actors;
    String[] tags;
    boolean HD;
    long filesize;
    String md5 = "origMD5";

    Media(File thefile) {
        this.file_location = thefile;
    }

    Media(String thefile) {
        this.file_location = new File(thefile);
    }
// snipped getters and setters
}
localhost
  • 1,253
  • 4
  • 18
  • 29
  • 1
    do you not think that you may want to search for parts of this Object like actors or length? If it is in a single object (BLOB maybe) then you will not be able to search, then what is the point of using a DB? – Scary Wombat Dec 11 '14 at 06:20
  • Yes, I do want to search for parts, that's why I'm asking the question. I think I will need to store the actor/tags info in a linked table somehow, so I can search for movies with a certain actor, etc. – localhost Dec 11 '14 at 07:22
  • This may help: https://docs.oracle.com/javase/tutorial/jdbc/basics/blob.html – Bryan Pendleton Dec 11 '14 at 14:29
  • @BryanPendleton CLOBs and BLOBs don't sound like what I need, their contents wouldn't be searchable. – localhost Dec 12 '14 at 00:30
  • @BryanPendleton Oh, now I think I understand why you suggested those, I am not trying to store the actual media in the db, just links to the file locations. – localhost Dec 13 '14 at 00:21

2 Answers2

3

ORM - Object Relational Maping is a concenpt that Hibernate and other frameworks use to store the data into database. It's an option to make easier to persist your data.

Using Hibernate Framework gives your opportunity to think about a database row like an object itself (Media object) there the columns of this row are Media object fields. By using an Pojo class you can have access to all of these fields and set/get the fields as you wish, and using Hibernate API you can persist the object into your database.

Depending on this concept you can choose to use Hibernate Framework or use default JDBC.

A good tutorial about hibernate you can find here: http://www.tutorialspoint.com/hibernate/index.htm

drgPP
  • 926
  • 2
  • 7
  • 22
  • Probably moot because it's just a few thousand items, but would there be a performance hit from using this as opposed to straight db tables, eg for searching for files matching multiple actors/tags? – localhost Dec 11 '14 at 09:58
  • The jdbc gives the better performance. For conclusions, if you are looking for performance, check this example: http://phpdao.com/hibernate_vs_jdbc/ – drgPP Dec 11 '14 at 10:03
  • I'm going through that tutorial now, seems very understandable and well-written so far. Hibernate does sound like it's what I'm looking for. Thanks. – localhost Dec 12 '14 at 01:42
1

I'm going to take a chance and say something which may be a bit controversial: Your Media class does not seem like a good abstraction for operations in a program. Rather it seems like just a collection of data. The fact that you need getters and setters (for all?) members also point in this direction.

Here is my (controversial) advice: Don't try to shoe-horn Media into being an object when it really isn't. Just create an ER (Entity-Relationship) model for your data, and create database tables to match. Then figure out which queries you need/want to support and create the necessary indices to speed things up. Then create classes/objects in you application to support queries/operations.

This idea that your program objects should should model real-world objects that is so popular in much OO-literature is IMHO plain wrong, unless maybe if your program is a kind of simulation. But 99% of all programs are not, they need objects (data+operations) that support what they are really doing. Which typically is something like fetch data from a db, copy it into a gui-model, and re-display.

Dyre
  • 547
  • 1
  • 3
  • 2