JDO architecture: One to many relationship and cascading deleting

Posted by user361897 on Stack Overflow See other posts from Stack Overflow or by user361897
Published on 2010-06-08T23:24:47Z Indexed on 2010/06/08 23:32 UTC
Read the original article Hit count: 167

I’m new to object oriented database designs and I’m trying to understand how I should be structuring my classes in JDO for google app engine, particularly one to many relationships.

Let’s say I’m building a structure for a department store where there are many departments, and each department has many products. So I’d want to have a class called Department, with a variable that is a list of a Product class.

@PersistenceCapable 
public class Department { 
    @PrimaryKey 
    @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY) 
    private String deptID; 

    @Persistent 
    private String departmentName; 

    @Persistent 
    private List<Product>; 

}

@PersistenceCapable 
public class Product { 
    @PrimaryKey 
    @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY) 
    private String productID; 

    @Persistent 
    private String productName; 

}

But one Product can be in more than one Department (like a battery could be in electronics and household supplies). So the next question is, how do I not duplicate data in the OOD world and have only one copy of product data in numerous departments? And the next question is, let’s say I delete out a particular product, how do each of the departments know it was deleted?

© Stack Overflow or respective owner

Related posts about java

Related posts about google-app-engine