• Post Reply Bookmark Topic Watch Topic
  • New Topic

storing custom object in sqllite db / seralizing a custom object  RSS feed

 
simon did
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hey

so i have this arraylist off a custom object that looks like this witch also contains a list off custom objects



code for second list off custom objects



how can i seralize this so i can store it in a sqllite db ?? i have trayed some code but it aint working ore well the seralizeobject metode is working but not the deserilize


this is how im calling the seralizing off the metods

im getting the following error

 
Knute Snortum
Sheriff
Posts: 4288
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My experience is that it's really hard to store data structures like these in a relational DB. I would create two tables, with ManufacturingJobHolder having a one-to-many relationship with ManufacturingMiniralHolder.

Libraries like Hibernate can help with this.
 
Campbell Ritchie
Marshal
Posts: 56599
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Serialisation and databases are completely different from each other. Don't confuse them.
There is something wrong with a class having a String blueprintID field. That does not look object‑oriented to me.

  • 1: Your classes are too large. 7 fields is far too many.
  • 2: You have some inappropriate (I think) types. Why an ID field when you can have the blueprint itself as a field?
  • 3: You do not have objects in the sense that objects encapsulate data and behaviour.
  • Your classes do nothing with any of the data, except possibly replace them with other data. The many setXXX methods with no internal checking breach encapsulation. There is nothing to stop somebody writing this sort of code:-Maybe you should have a mineral class which encapsulates type ID and price. Then you can have a mineral consignment class which encapsulates mineral and amount.

    There is a nice introductory databases tutorial in the Java Tutorials.
     
    Ulf Dittmer
    Rancher
    Posts: 42972
    73
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Why are you trying to use serialization instead of storing the attributes directly in the DB like one would normally do? http://developer.android.com/guide/topics/data/data-storage.html#db

    Your classes are too large. 7 fields is far too many.

    I disagree. 7 is a small number of attributes for a DB table, and this looks like a DAO or DTO to me. But even if it's not, 7 would still not be too many, much less "far too many".

    You do not have objects in the sense that objects encapsulate data and behaviour.

    Generally I'd agree, but for DAO/DTO objects this is normal.
     
    simon did
    Greenhorn
    Posts: 5
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    hey thanks for the replays :P

    2: You have some inappropriate (I think) types. Why an ID field when you can have the blueprint itself as a field?

    blueprintid and typeid is not the same....


    3: You do not have objects in the sense that objects encapsulate data and behaviour.


    self-taught java developer so not the bedst at good Practices object programming

    Why are you trying to use serialization instead of storing the attributes directly in the DB like one would normally do?

    the may problem is that it's an arraylist off a custom object with i can't just turn in to text and store in a sqllite db as fare as i understand...

    so im currently not having truble storing any thing othere then this list


    ill deafently read out on what DAO/DTO means :P

    any idears on how i can store that arraylist in my sqllite db ?

    since it sounds like you guys know a lot about development due you have some good links about good practice for coding ?
     
    Knute Snortum
    Sheriff
    Posts: 4288
    127
    Chrome Eclipse IDE Java Postgres Database VI Editor
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    The way to store an object in a DB is to store one object per row with the columns being the fields. If the fields can translate into the DB, like ints, Strings, sometimes dates, then you're done. If a field is itself an object, then this secondary object needs it's own table and ID. Store only the ID in the original object's row. If the field is not scalar, that is, it has parts like an array or a set, you need a new table with each row being one of the elements of the array, and a combined key of the original object ID and the element ID.

    If this sounds complex, it's because it is. ORM like Hibernate help to ease this problem by letting you think of objects getting passed in the DB, instead of rows being inserted. But you still have to map the fields of the objects to something the DB understands.
     
    Ulf Dittmer
    Rancher
    Posts: 42972
    73
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    If this is really a question about Android -Simon, please confirm or disconfirm - then neither JDBC nor Hibernate are likely to be options.
     
    simon did
    Greenhorn
    Posts: 5
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    yes this code is going to be jused in a android app
     
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!