-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Entity Inheritance Mapping confusion
PostPosted: Mon Jul 02, 2007 10:27 pm 
Beginner
Beginner

Joined: Fri Jul 28, 2006 12:01 pm
Posts: 21
I am a little confused when it comes to mapping inheritance in JPA

I have an entity (AddressLookup) which has a subclass (Landmark). The parent entity is related to another entity (ServiceRequest) OneToMany.

I am using the Table per subclass (JOINED) mapping pattern.

AddressLookup
Code:
@Entity
@Inheritance(strategy=InheritanceType.JOINED)
@Table(name = "ADDRESS_LOOKUP")
@DiscriminatorColumn(name="ADDRESS_TYPE",discriminatorType=DiscriminatorType.STRING)
@DiscriminatorValue("ADDRESS")

public class AddressLookup implements Serializable {

    @Id
    @Column(name = "ADDRESS_LOOKUP_ID", nullable = false)       
    private Long addressLookupId;

    @OneToMany(cascade = CascadeType.ALL, mappedBy="addressLookup")
    private Collection<ServiceRequest> serviceRequestCollection;
...


Landmark
Code:
@Entity
@PrimaryKeyJoinColumn(name="LANDMARK_ID")
@Table(name = "LANDMARK")
@DiscriminatorValue("LANDMARK")
public class Landmark extends AddressLookup implements Serializable {
    @Column(name = "LANDMARK_ID", nullable = false, insertable=false, updatable=false)
    private Long landmarkId
...


ServiceRequest

Code:
@Entity
@Table(name = "SERVICE_REQUEST")
public class ServiceRequest implements Serializable {

    @Id
    @Column(name = "REQUEST_ID", nullable = false)
    private Long requestId;

    @ManyToOne
    @JoinColumn(name="ADDRESS_LOOKUP_ID", referencedColumnName="ADDRESS_LOOKUP_ID")
    private AddressLookup addressLookup;
...


How do I refer to the landmarks collections from a ServiceRequest?

In order for the following to be valid, should I map Landmark to AddressLookup OneToOne?

Landmark landmark = serviceRequest.getAddressLookup.getLandmark();

It is not a problem going the other way since Landmark inherits getServiceRequestCollection() from AddressLookup but ServiceRequest knows nothing of the subclass Landmark.

Thanks for any help.

-Brian


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.