class-table-inheritance

How to map collection of each subclass from same hierarchy onto one owning class?

十年热恋 提交于 2019-12-04 17:17:38
Does anyone know how to map a collection of each subclass from the same hierarchy onto one owning class, using JPA 2.0 annotations, backed by Hibernate 4.0.0.Final? Bit convoluted, so here's an example. Hierarchy classes look like this: @Entity @Cacheable(true) @Table(name = "hierarcicals") @Inheritance(strategy=InheritanceType.SINGLE_TABLE) @DiscriminatorColumn(name = "class", discriminatorType = DiscriminatorType.STRING) public abstract class MySuperClass { ... @Entity @DiscriminatorValue("SubClassOne") public class SubClassOne extends MySuperClass { ... @ManyToOne(fetch = FetchType.LAZY)

Class Table Inheritance in Rails 3

╄→尐↘猪︶ㄣ 提交于 2019-12-04 09:13:49
问题 I'm currently working on a Rails 3 application that looks like it might need to use Class Table Inheritance for a couple of models. A simplified example of what's going on is this. I have a class called Person with general attributes like name, email, password which are common to all types of people in the application and used for authentication. There are two subclasses to Person (or two types of people...), Driver and Passenger. Both of these subclasses share the generic attributes of

Avoid Circular Dependency

你离开我真会死。 提交于 2019-12-03 07:42:34
I am developing a travel management application. The design in question is something like following : Each person in a tour is designated as a Traveler. Each Traveler has a Passport. Now, a Traveler can be a MainMember or a SubMember, depending on whether or not he is the head of the family. A MainMember decides stuff like TourPackage, total amount for his travelling family, etc. A SubMember is dependent on the MainMember while travelling. So, if a MainMember is deleted, all its SubMembers have to be deleted as well. So, A Traveler has a Passport. (One to One relationship) A Traveler is either

Class Table Inheritance in Rails 3

て烟熏妆下的殇ゞ 提交于 2019-12-03 02:15:59
I'm currently working on a Rails 3 application that looks like it might need to use Class Table Inheritance for a couple of models. A simplified example of what's going on is this. I have a class called Person with general attributes like name, email, password which are common to all types of people in the application and used for authentication. There are two subclasses to Person (or two types of people...), Driver and Passenger. Both of these subclasses share the generic attributes of Person but then have specific additional attributes which are unique to themselves. (for example a Driver

Doctrine2: OneToMany on mapped superclass

流过昼夜 提交于 2019-12-01 01:10:09
问题 My DB structure is as follows: work: CTI table Work MappedSuperclass table AbstractImageWork which extends Work final table PhotoWork which extends AbstractImageWork comment: MappedSuperclass table Comment final table WorkComment which extends Comment WorkComment has a ManyToOne relation to Work : @ManyToOne(targetEntity="Work", inversedBy="comments") Work has a OneToMany relation to WorkComment : @OneToMany(targetEntity="WorkComment", mappedBy="work") The problem is that Doctrine gives me

How to implement a super class, sub class relationship in the database?

為{幸葍}努か 提交于 2019-11-30 05:19:15
If I have a class called animal, dog and fish is the subclass. The animal have attribute called "color". Dog have the attribute called "tail length", and the fish don't have this attribute. Fish have the attribute called "weight", the dog don't have this attribute. So, I want to design a database to store this information. What should I do? Here is some ideas: Idea 1: Making an animal table, and the table have type, to find what kind of animal, if it is a dog, just get the result from dog table. Animal: color:String type:int Type: Dog:0 Fish:1 Dog: TailLength:int Fish: Weight:int Idea 2: Store

How to change and entity type in Doctrine2 CTI Inheritance

纵饮孤独 提交于 2019-11-29 06:34:51
How (if possible at all) do you change the entity type with Doctrine2, using it's Class Table Inheritance? Let's say I have a Person parent class type and two inherited types Employe and Client . My system allows to create a Person and specify it's type - that's fairly easy to implement - but I'd also like to be able to change the person from an Employe to a Client, while maintaining the Person -level information (it's id and other associated records). Is there a simple way to do this with Doctrine2? I was looking for this behaviour yesterday also. In the end, after speaking with people in

How to implement a super class, sub class relationship in the database?

浪子不回头ぞ 提交于 2019-11-29 02:53:16
问题 If I have a class called animal, dog and fish is the subclass. The animal have attribute called "color". Dog have the attribute called "tail length", and the fish don't have this attribute. Fish have the attribute called "weight", the dog don't have this attribute. So, I want to design a database to store this information. What should I do? Here is some ideas: Idea 1: Making an animal table, and the table have type, to find what kind of animal, if it is a dog, just get the result from dog

How do we implement an IS-A Relationship?

自闭症网瘾萝莉.ら 提交于 2019-11-28 16:06:13
We implement an One-to-Many relationship by adding one Table's PK, as FK to the other Table. We implement a Many-to-Many relationship by adding 2 Table's PKs to a third Table. How do we implement an IS-A Relationship ? The Entities are TECHNICIAN and ADMINISTRATIVE which both are EMPLOYEE. I could just use an extra field in the Table EMPLOYEE(id, name, surname, role , ...AdminFields..., ...TechFields...) but i would like to explore the IS-A option. EDIT: I did as Donnie suggested, but without the role field. I did as Donnie suggested, but without the role field, because it complicates things.

Doctrine 2.1 - Map entity to multiple tables

邮差的信 提交于 2019-11-28 13:46:13
I have the following database situation: wp_users (user table generated by wordpress) ID | user_login | ... wp_sp_user (extension to the wp_users table) ID (FK) | surname | address | ... Now I've already been trying for hours to "fuse" those two tables into one single User entity, e.g: class User { var ID; var user_login; var surname; var address; ... } Is there any way to accomplish such a mapping without modifying the wp_user table (which I don't want to do for updating reasons)? Some times database refactoring is not possible or the table has his own "raison d'être". In this cases you can