-->
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.  [ 10 posts ] 
Author Message
 Post subject: Strange Error with discriminated table and abstract ancestor
PostPosted: Mon Dec 11, 2017 11:44 am 
Beginner
Beginner

Joined: Thu Jan 12, 2006 6:32 pm
Posts: 39
Location: Austin, Tx, USA, NA, Sol 3
Using 5.2.12.Final. I have a simple main class that creates an EntityManager instance to validate my mappings (and create the schema).

I have a parent table (Applicant) that has a child table (ProofDocument). The latter of which is abstract and has the @DiscriminatorColumn and @DiscriminatorOptions annotations.

ProofDocument has two descendants: ProofDocumentId and ProofDocumentSsn.

The @OneToMany linkages from Applicant look like this:

Code:
   @Fetch(FetchMode.SELECT)
   @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "applicant", orphanRemoval = true)
   @Where(clause = "IDPR_PROOF_TYP = '2 '") // needs trailing space
   public List<ProofDocumentId> getProofDocumentIdCollection() {
      return proofDocumentIdCollection;
   }

   @Fetch(FetchMode.SELECT)
   @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "applicant", orphanRemoval = true)
   @Where(clause = "IDPR_PROOF_TYP = '1 '") // needs trailing space
   public List<ProofDocumentSsn> getProofDocumentSsnCollection() {
      return proofDocumentSsnCollection;
   }


(Setters removed for brevity.)

The ancestor ProofDocument references the Applicant (parent) like so:

Code:
   @JoinColumn(name = "IDPR_PERSON_ID", insertable = false, nullable = false, updatable = false,
      foreignKey = @ForeignKey(name = "fk_pod_a__person_id"))
   @ManyToOne(fetch = FetchType.LAZY, optional = false)
   @NotNull(message = "proofDocument.applicant.required")
   public Applicant getApplicant() {
      return applicant;
   }


ProofDocument is abstract because an instance of it makes no sense, only an instance of the descendants is valid.

So, why am I getting:

Code:
org.hibernate.AnnotationException: mappedBy reference an unknown target entity property: a.b.c.ProofDocumentId.applicant in a.b.c.Applicant.proofDocumentIdCollection


when it is clearly in the ancestor class of ProofDocumentId/Ssn. I should NOT have to move Applicant from ancestor to descendant to clear this error, but that's what I had to do.


Top
 Profile  
 
 Post subject: Re: Strange Error with discriminated table and abstract ancestor
PostPosted: Mon Dec 11, 2017 12:52 pm 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1628
Location: Romania
Did you add @MappedSupercclass in the Applicant class?


Top
 Profile  
 
 Post subject: Re: Strange Error with discriminated table and abstract ancestor
PostPosted: Mon Dec 11, 2017 8:32 pm 
Beginner
Beginner

Joined: Thu Jan 12, 2006 6:32 pm
Posts: 39
Location: Austin, Tx, USA, NA, Sol 3
I assume you meant the ProofDocument class, not Applicant. Added it, to no effect.


Top
 Profile  
 
 Post subject: Re: Strange Error with discriminated table and abstract ancestor
PostPosted: Tue Dec 12, 2017 6:21 am 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1628
Location: Romania
I still don't understand how your entities look like. It's much easier if you just post them entirely.


Top
 Profile  
 
 Post subject: Re: Strange Error with discriminated table and abstract ancestor
PostPosted: Tue Dec 12, 2017 9:53 am 
Beginner
Beginner

Joined: Thu Jan 12, 2006 6:32 pm
Posts: 39
Location: Austin, Tx, USA, NA, Sol 3
The Parent:

Code:
@Entity
@Table(name = "APPLICANT")
public class Applicant implements Serializable {
/* fields */

/* children */
   private List<ProofDocumentId> proofDocumentIdCollection;
   private List<ProofDocumentSsn> proofDocumentSsnCollection;

   @Fetch(FetchMode.SELECT)
   @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "applicant", orphanRemoval = true)
   @Where(clause = "IDPR_PROOF_TYP = '2 '") // needs trailing space
   public List<ProofDocumentId> getProofDocumentIdCollection() {
      return proofDocumentIdCollection;
   }

   public void setProofDocumentIdCollection(List<ProofDocumentId> proofDocumentIdCollection) {
      this.proofDocumentIdCollection = proofDocumentIdCollection;
   }

   @Fetch(FetchMode.SELECT)
   @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "applicant", orphanRemoval = true)
   @Where(clause = "IDPR_PROOF_TYP = '1 '") // needs trailing space
   public List<ProofDocumentSsn> getProofDocumentSsnCollection() {
      return proofDocumentSsnCollection;
   }

   public void setProofDocumentSsnCollection(List<ProofDocumentSsn> proofDocumentSsnCollection) {
      this.proofDocumentSsnCollection = proofDocumentSsnCollection;
   }



The child ancestor, which is abstract.

Code:
@DiscriminatorColumn(name = "IDPR_PROOF_TYP", discriminatorType = DiscriminatorType.STRING)
@DiscriminatorOptions(force = true, insert = false)
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@MappedSuperclass
@Table(name = "PROOF_DOCUMENT")
public abstract class ProofDocument implements Serializable {
/* fields */

   private Applicant applicant; /* parent reference */

   @JoinColumn(name = "IDPR_PERSON_ID", insertable = false, nullable = false, updatable = false,
      foreignKey = @ForeignKey(name = "fk_pod_a__app_id"))
   @ManyToOne(fetch = FetchType.LAZY, optional = false)
   @NotNull(message = "proofDocument.applicant.required")
   public Applicant getApplicant() {
      return applicant;
   }
   public void setApplicant(Applicant applicant) {
      this.applicant = applicant;
   }   


One of the two descendants.

Code:
@DiscriminatorValue("2 ") // see: ProofDocumentProofTypeEnum.ID.getValue())
@Entity
public class ProofDocumentId extends ProofDocument implements Serializable {

   private static final long serialVersionUID = 1L;

   public ProofDocumentId() {
      super();
      setProofDocumentTypeEnum(ProofDocumentTypeEnum.ID);
   }
}


This is what I think I should be able to do. But because of this error, I have to put the Application back reference in the descendant, not the ancestor.


Top
 Profile  
 
 Post subject: Re: Strange Error with discriminated table and abstract ancestor
PostPosted: Tue Dec 12, 2017 10:12 am 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1628
Location: Romania
You should never combine @Inheritance with @MappedSuperclass. It's an illegal mapping.

Code:
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@MappedSuperclass


Top
 Profile  
 
 Post subject: Re: Strange Error with discriminated table and abstract ancestor
PostPosted: Tue Dec 12, 2017 5:47 pm 
Beginner
Beginner

Joined: Thu Jan 12, 2006 6:32 pm
Posts: 39
Location: Austin, Tx, USA, NA, Sol 3
So, does that mean that what I want to do is impossible:

specify the @ManyToOne in the ancestor rather than the descendant?


Top
 Profile  
 
 Post subject: Re: Strange Error with discriminated table and abstract ancestor
PostPosted: Wed Dec 13, 2017 2:30 am 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1628
Location: Romania
1. Try making ProofDocument an entity, like this:

Code:
@DiscriminatorColumn(name = "IDPR_PROOF_TYP", discriminatorType = DiscriminatorType.STRING)
@DiscriminatorOptions(force = true, insert = false)
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@Entity
@Table(name = "PROOF_DOCUMENT")
public class ProofDocument implements Serializable {
    ...
}


2. The bidirectional mapped is also wrong because the @ManyToOne side is marlet with insertbale/updatable=false:

Code:
@JoinColumn(name = "IDPR_PERSON_ID", nullable = false,
  foreignKey = @ForeignKey(name = "fk_pod_a__app_id"))
@ManyToOne(fetch = FetchType.LAZY, optional = false)
@NotNull(message = "proofDocument.applicant.required")
public Applicant getApplicant() {
  return applicant;
}


You need this side to control the association because the other side is ignored, being mappedBy.


Top
 Profile  
 
 Post subject: Re: Strange Error with discriminated table and abstract ancestor
PostPosted: Wed Dec 13, 2017 12:55 pm 
Beginner
Beginner

Joined: Thu Jan 12, 2006 6:32 pm
Posts: 39
Location: Austin, Tx, USA, NA, Sol 3
I made the changes you suggested, and the children are as they always were:

Code:
@DiscriminatorColumn(name = "IDPR_PROOF_TYP", discriminatorType = DiscriminatorType.STRING)
@DiscriminatorOptions(force = true, insert = false)
@Entity
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@Table(schema = "DLNDLF", name = "PROOF_OF_ID_INFO")
public abstract class ProofDocument extends BaseDLSDataEntity<Long> implements Serializable {
...
   @JoinColumn(name = "IDPR_PERSON_ID", nullable = false,
      foreignKey = @ForeignKey(name = "fk_podid_a__person_id"))
   @ManyToOne(fetch = FetchType.LAZY, optional = false)
   @NotNull(message = "proofDocument.applicant.required")
   public Applicant getApplicant() {
      return applicant;
   }



Code:
@DiscriminatorValue("2 ") // see: ProofDocumentProofTypeEnum.ID.getValue())
@Entity
public class ProofDocumentId extends ProofDocument implements Serializable {


Code:
@DiscriminatorValue("1 ") // see: ProofOfDocumentDocumentTypeEnum.SSN.getValue())
@Entity
public class ProofDocumentSsn extends ProofDocument implements Serializable {


Code:
   private List<ProofDocumentId> proofDocumentIdCollection;
   private List<ProofDocumentSsn> proofDocumentSsnCollection;

   @Fetch(FetchMode.SELECT)
   @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "applicant", orphanRemoval = true)
   @Where(clause = "IDPR_PROOF_TYP = '2 '") // needs trailing space
   public List<ProofDocumentId> getProofDocumentIdCollection() {
      return proofDocumentIdCollection;
   }

   @Fetch(FetchMode.SELECT)
   @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "applicant", orphanRemoval = true)
   @Where(clause = "IDPR_PROOF_TYP = '1 '") // needs trailing space
   public List<ProofDocumentSsn> getProofDocumentSsnCollection() {
      return proofDocumentSsnCollection;
   }



yet the error persists:

Code:
org.hibernate.AnnotationException: mappedBy reference an unknown target entity property: a.b.c.ProofDocumentId.applicant in a.b.c.Applicant.proofDocumentIdCollection


This is very weird, its like Hibernate cannot see the Applicant entity that is part of the abstract ancestor.


Top
 Profile  
 
 Post subject: Re: Strange Error with discriminated table and abstract ancestor
PostPosted: Wed Dec 13, 2017 1:20 pm 
Beginner
Beginner

Joined: Thu Jan 12, 2006 6:32 pm
Posts: 39
Location: Austin, Tx, USA, NA, Sol 3
I found this article which appears to be encountering the same problem but I don't understand the answer.

https://stackoverflow.com/questions/763 ... rty-in-jpa


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

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.