-->
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.  [ 2 posts ] 
Author Message
 Post subject: [SOLVED?]OneToMany relation that is also id in owner fails.
PostPosted: Fri Dec 10, 2010 5:33 am 
Newbie

Joined: Fri Dec 10, 2010 4:55 am
Posts: 2
I have 2 entities that are related through both a onetomany and a manytoone.
The owning entity uses a composite primairy key that consists of the foreign key from the owned entity.

If I remove the @Id in the owning entity (at getProfileType() in IProfileTypeImpl). Everyting seems to work (except for the fact that the key definition is incomplete of course), if I keep it there, I get an exception:
Code:
mappedBy reference an unknown target entity property: IProfileTypeImpl.profileType in ProfileTypeImpl.IProfileTypes


Alternative I could use an embedded entity to define my composite key, but will this solve my problem and will I still be able to implement the getters and setters from the interfaces properly?

The Owner Entity (IProfileTypeImpl):
Code:
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import com.chicagometallic.productmaster.shared.IProfileType;
import com.chicagometallic.productmaster.shared.Language;
import com.chicagometallic.productmaster.shared.ProfileType;

@Entity
@Table(name = "i_profiletype")
public class IProfileTypeImpl extends PMDbEntryImpl implements IProfileType {

    /**
     *
     */
    private static final long serialVersionUID = -4980796880003075949L;

    private String profileTypeName;
    private ProfileType profileType;
    private Language language;

    public IProfileTypeImpl() {
    }

    @Override
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @ManyToOne(targetEntity = LanguageImpl.class)
    @JoinColumn(name = "languageid")
    public Language getLanguage() {
   return this.language;
    }

    @Override
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @ManyToOne(targetEntity = ProfileTypeImpl.class)
    @JoinColumn(name = "profiletypeid")
    public ProfileType getProfileType() {
   return this.profileType;
    }

    @Override
    @Basic
    @Column(name = "profiletypename", length = 254)
    public String getProfileTypeName() {
   return this.profileTypeName;
    }

    @Override
    public void setLanguage(final Language language) {
   this.language = language;
    }

    @Override
    public void setProfileType(final ProfileType profileType) {
   this.profileType = profileType;
    }

    @Override
    public void setProfileTypeName(final String profileTypeName) {
   this.profileTypeName = profileTypeName;
    }
}


The owned entity (ProfileTypeImpl) :
Code:
import java.util.List;

import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import com.chicagometallic.productmaster.shared.IProfileType;
import com.chicagometallic.productmaster.shared.ProfileType;
import com.chicagometallic.productmaster.shared.SystemRelation;

@Entity
@Table(name = "profiletype")
public class ProfileTypeImpl extends PMDbEntryImpl implements ProfileType {

    /**
     *
     */
    private static final long serialVersionUID = -1781738964008203370L;

    private Boolean defaultProfileType;
    private Integer profileTypeId;
    private List<SystemRelation> systemRelations;
    private List<IProfileType> iProfileTypes;

    public ProfileTypeImpl() {
    }

    @Override
    @Basic
    @Column(name = "defaultprofiletype")
    public Boolean isDefaultProfileType() {
   return this.defaultProfileType;
    }

    @Override
    @Basic
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Column(name = "profiletypeid", scale = 8, columnDefinition = "mediumint")
    public Integer getProfileTypeId() {
   return this.profileTypeId;
    }

    @Override
    @OneToMany(targetEntity = SystemRelationImpl.class)
    @JoinColumn(name = "profileType")
    public List<SystemRelation> getSystemRelations() {
   return this.systemRelations;
    }

    @Override
    public void setDefaultProfileType(final Boolean defaultProfileType) {
   this.defaultProfileType = defaultProfileType;
    }

    @Override
    public void setProfileTypeId(final Integer profileTypeId) {
   this.profileTypeId = profileTypeId;
    }

    @Override
    public void setSystemRelations(final List<SystemRelation> systemRelations) {
   this.systemRelations = systemRelations;
    }

    @Override
    @OneToMany(targetEntity = IProfileTypeImpl.class, mappedBy = "profileType")
    public List<IProfileType> getIProfileTypes() {
   return this.iProfileTypes;
    }

    @Override
    public void setIProfileTypes(final List<IProfileType> iProfileTypes) {
   this.iProfileTypes = iProfileTypes;
    }

}


Last edited by zubzub on Fri Dec 10, 2010 6:18 am, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: OneToMany relation that is also id in owner fails.
PostPosted: Fri Dec 10, 2010 6:17 am 
Newbie

Joined: Fri Dec 10, 2010 4:55 am
Posts: 2
Ok I seem to have solved it (although I need to test it more...)

For the owner entity (IProfileType):

Code:
    @Override
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @ManyToOne(targetEntity = ProfileTypeImpl.class)
    @JoinColumn(name = "profiletypeid", referencedColumnName = "profiletypeid")
    public ProfileType getProfileType() {
   return this.profileType;
    }


for the owned entity (ProfileType):
Code:
    @Override
    @OneToMany(targetEntity = IProfileTypeImpl.class)
    @JoinColumn(name = "profiletypeid")
    public List<IProfileType> getIProfileTypes() {
   return this.iProfileTypes;
    }


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.