Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Weak Entities Support #101

Open
jpitchardu opened this issue Jan 17, 2017 · 2 comments
Open

Weak Entities Support #101

jpitchardu opened this issue Jan 17, 2017 · 2 comments

Comments

@jpitchardu
Copy link

jpitchardu commented Jan 17, 2017

Let's say I've a Client and Seller entities, and both have an Address, which is unique for entity, currently the way to do this would be to have each of the fields of the Address on the entities like

public class Client {
    private String name;
    private String st1;
    private String st2;
 }

public class Seller {
    private String name;
    private String st1;
    private String st2;
}

It would be really, really good to be able to do something like:

public class Client {
    private String name;
    private Complex<Address> address;
}

public class Seller {
    private String name;
    private Complex<Address> address;
}

public class Address {
    private String st1;
    private String st2;
}
@Kcorab
Copy link

Kcorab commented Jul 21, 2017

I see no problems. Why you don't use the address as an entity? :-)

public abstract class AEntity {

    @DatabaseField(generatedId = true, columnName = "ID", canBeNull = false)
    private Integer id;

    // setter, getter
}

@DatabaseTable(tableName = "CLIENT")
public class Client extends AEntity {

    @DatabaseField(foreign = true, columnName = "ID_ADDRESS")
    private Address address;
    // setter, getter
}

@DatabaseTable(tableName = "SELLER")
public class Seller extends AEntity {

    @DatabaseField(foreign = true, columnName = "ID_ADDRESS")
    private Address address;
    // setter, getter
}

@DatabaseTable(tableName = "ADDRESS")
public class Address extends AEntity {

    @DatabaseField(columnName = "ST1")
    private String st1;
    @DatabaseField(columnName = "ST2")
    private String st2;

    // setter, getter
}

An equivalent of @Embeddable like hibernate doesn't exist for ORMLite.

@jpitchardu
Copy link
Author

@Kcorab yeah that's one solution, but Address is considered a Weak entity, meaning that it doesn't have any sense to have an Address without a Seller, and a Seller can only have one Address, so the right way to map that relationship would be with address fields on the Seller and Client table

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants