-->
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: JPA OneToMany MappedBy relationships
PostPosted: Thu Sep 15, 2016 4:04 am 
Newbie

Joined: Thu Sep 15, 2016 4:01 am
Posts: 1
I have three classes, Site, GoupIP and IP

A Site has one or many GrouIPs.
A GroupIP has one or many IPs.

Here is the code:

Site

Code:
@Entity
    @Table(name = "site")
    public class Site implements Serializable {
    private Set<GroupIp> groups;

    @OneToMany(mappedBy = "site", fetch = FetchType.EAGER, cascade =CascadeType.ALL)
   public Set<GroupIp> getGroups() {
      return groups;
   }

    public void setGroups(Set<GroupIp> groups) {
      this.groups = groups;
   }

    }


GroupIP

Code:
@Entity
    @Table(name = "groupip")
    public class GroupIp implements Serializable {
    private Set<Ip> ips;
    private Site site;

    @ManyToOne(cascade = CascadeType.MERGE)
    @JoinColumn(name = "site_id")
    public Site getSite() {
   return site;
    }

    @OneToMany(mappedBy = "groupip", fetch = FetchType.EAGER, cascade =CascadeType.ALL)
   public Set<Ip> getIps() {
      return ips;
   }

    public void setIps(Set<Ip> ips) {
      this.ips= ips;
   }

    }




IP

Code:
@Entity
    @Table(name = "ip")
    public class Ip implements Serializable {
    private GroupIp groupIp;

    @ManyToOne(targetEntity = GroupIp.class,cascade = CascadeType.MERGE)
   @JoinColumn(name = "groupip_id", nullable=false)
   public GroupIp getGroupIp() {
   return groupIp;
   }

    public void setGroupIp(GroupIp groupIp) {
         this.groupIp = groupIp;
   }

    }



On GroupIp class, I m getting:

*In attribute 'ips', the "mapped by" value 'groupip' cannot be resolved to an attribute on the target entity.*

Whats wrong on my code ??


Top
 Profile  
 
 Post subject: Re: JPA OneToMany MappedBy relationships
PostPosted: Thu Sep 15, 2016 4:56 am 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1628
Location: Romania
Instead of:

Code:
@OneToMany(mappedBy = "groupip", fetch = FetchType.EAGER, cascade =CascadeType.ALL)


try with:

Code:
@OneToMany(mappedBy = "groupIp", fetch = FetchType.EAGER, cascade =CascadeType.ALL)


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.