开发者

Is there an ORM that supports composition w/o Joins

开发者 https://www.devze.com 2023-02-09 06:06 出处:网络
EDIT: Changed title from \"inheritance\" to \"composition\".Left body of question unchanged. I\'m curious if there is an ORM tool that supports inheritance w/o creating separate tables that have to b

EDIT: Changed title from "inheritance" to "composition". Left body of question unchanged.

I'm curious if there is an ORM tool that supports inheritance w/o creating separate tables that have to be joined.

Simple example. Assume a table of customers, with a Bill-to address, and a table of vendors, with a remit-to address. Keep it simple and assume one address each, not a child table of addresses for each.

These addresses will have a handful of values in common: address 1, address 2, city, state/province, postal code. So let's say I'd have a class "addressBlock" and I want the customers and vendors to inherit from this class, and possibly from other classes. But I do not want separate tables that have to be joined, I want the columns in the customer and vendor tables respectively.

Is there an ORM that supports this?

The closest question I have found on StackOverflow that might be the same question is linked below, but I can't quite figure if the OP is asking what I am asking. He开发者_StackOverflow社区 seems to be asking about foregoing inheritance precisely because there will be multiple tables. I'm looking for the case where you can use inheritance w/o generating the multiple tables.

Model inheritance approach with Django's ORM


JPA (Java Persistence API, implemented by Hibernate, EclipseLink and others) supports this : You would define an Address POJO, mark it as "embeddable", and have two entities (Customer and Vendor) having each a field of type Address (marked as "embedded"). The fields of the customer address would be mapped to columns in the Customer table, and the fields of the vendor address would be mapped to columns in the Vendor table.

Note that there's no inheritance here. Inheritance is for is-a relationships. A vendor is not an address, and a customer is not an address either. There is composition, though, because a vendor has an address, and a customer has an address.

0

精彩评论

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