Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Object-Relational Mapping question

Options
  • 25-12-2009 9:28pm
    #1
    Closed Accounts Posts: 267 ✭✭


    Hi,

    I'm trying to do up an ORM structure for a Java project I'm doing. I was just using Objects and HashMaps up until now but it's getting far too complicated for that.

    The software basically has a directed graph structure (i.e. http://en.wikipedia.org/wiki/Graph_%28data_structure%29 ) that the user can draw, and stores properties about each 'node' in the graph.

    Let's say there's 3 types of nodes, NodeType1, NodeType2, NodeType3. They all have different properties associated with them.

    So the graph structure looks like this:

    Node
    ID   ParentsID  Name
    1    2          Node 1
    2    3          Node 2
    etc...
    
    (ParentsID is one-to-many, keeps track of the parents of each node on the digraph)

    Parent
    ID   NodeID
    2     2
    2     3
    etc...
    

    Now, as per this article http://www.objectmatter.com/vbsf/docs/maptool/ormapping.html I can deal with the different node types by one-to-one mapping of NodeTypeX to a Node ID, e.g.

    NodeType 1
    ID    NodeID   Value1    Value2
    

    That's all fine. Here's where it gets a bit tricky:

    Some of the NodeTypes store values for each parent of that node, so I need to link them to a separate table with that e.g.


    NodeType 2
    ID    NodeID   Value1    ParentValuesID
    


    ParentValue
    ID     NodeID     Value
    

    My problem here is that the ParentValue table would have to be synchronised with the Parent table, as each parent of the node would need a value. When a parent to a node is added or removed I need it to change both the Parent and ParentValue tables.

    What's standard practice for this situation? Can this be handled automatically by Hibernate/JPA etc? Will they have to be synchronised manually?



    Part 2


    It gets more complicated. The software is for Bayesian networks.

    One type of node stores a Conditional Probability Table a bit like this (the table at the bottom):

    WetGrass.gif

    So this node needs to store a table of arbitrary length (the states aren't limited to false/true). Is this possible with a relational database?

    This is all I have so far
    ObservedNode
    ID     NodeID     StatesID (one-to-many)
    

    State
    ID    Name
    

    Then come up with some way of permutating these into one table with support for redundant states.

    I have no idea where to begin with this. :confused: Any help appreciated.


Comments

Advertisement