开发者

JDO architecture: One to many relationship and cascading deleting

开发者 https://www.devze.com 2023-01-03 06:34 出处:网络
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.

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 开发者_Python百科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> products; 

}

@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?


You need to add the following to the relevant member of the Department class. Also, see the section regarding this in the App Engine documentation.

@Persistent
@Element(dependent = "true")
private List<Product> products; 
0

精彩评论

暂无评论...
验证码 换一张
取 消