-->
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.  [ 8 posts ] 
Author Message
 Post subject: mappedBy reference an unknown target entity property
PostPosted: Sun Aug 09, 2009 12:22 pm 
Newbie

Joined: Sun Aug 09, 2009 12:14 pm
Posts: 16
i have 3 classes :
@Entity
@Table(name="companies")
public class Company implements Serializable {


private static final long serialVersionUID = -3322113303362981686L;

@Id
@Column(name="CMP_COMPANY_ID",nullable=false)
@GeneratedValue(strategy = GenerationType.AUTO)
private Integer id;

@Column(name="CMP_COMPANY_NAME",nullable=false)
private String name;

@OneToMany(mappedBy="company")
private Set<Item> items;


public Integer getId() {
return id;
}

public void setId(Integer id) {
this.id = id;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public Set<Item> getItems() {
return items;
}

public void setItems(Set<Item> items) {
this.items = items;
}
}

Items class :

Entity
@Table(name = "ELC_ITEMS")
public class Item implements Serializable{

private static final long serialVersionUID = 8635086262992868784L;

@EmbeddedId
public ItemPK itemPK;

@Column(name = "ITM_ITEM_NAME")
private String itemName;
}
And :
@Embeddable
public class ItemPK implements Serializable {


private static final long serialVersionUID = -5177491823551943094L;

@ManyToOne
@JoinColumn(name="ITM_COMP_ID", referencedColumnName="CMP_COMPANY_ID")
protected Company company;

public Company getCompany() {
return company;
}

public void setCompany(Company company) {
this.company = company;
}

@Column(name="ITM_ITEM_CODE", nullable=false)
private String itemCode;

public String getItemCode() {
return itemCode;
}

public void setItemCode(String itemCode) {
this.itemCode = itemCode;
}

public boolean equals(Object other) {
if (other instanceof ItemPK) {
final ItemPK otherItemPK = (ItemPK) other;
return (otherItemPK.company.equals(company) && otherItemPK.itemCode.equals(itemCode));
}
return false;
}

public int hashCode() {
return super.hashCode();
}


}

When i run the application i get this stuck trace:

Caused by: org.hibernate.AnnotationException: mappedBy reference an unknown target entity property: model.Item.company in model.Company.items
at org.hibernate.cfg.annotations.CollectionBinder.bindStarToManySecondPass(CollectionBinder.java:578)
at org.hibernate.cfg.annotations.CollectionBinder$1.secondPass(CollectionBinder.java:543)
at org.hibernate.cfg.CollectionSecondPass.doSecondPass(CollectionSecondPass.java:43)
at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1130)
at org.hibernate.cfg.AnnotationConfiguration.secondPassCompile(AnnotationConfiguration.java:329)
at org.hibernate.cfg.Configuration.buildMappings(Configuration.java:1115)
at org.hibernate.ejb.Ejb3Configuration.buildMappings(Ejb3Configuration.java:1226)
at org.hibernate.ejb.EventListenerConfigurator.configure(EventListenerConfigurator.java:173)
at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:854)
at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:425)
at org.hibernate.ejb.HibernatePersistence.createContainerEntityManagerFactory(HibernatePersistence.java:131)
at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:224)
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:291)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1369)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1335)

What is wrong with my mapping ?


Top
 Profile  
 
 Post subject: Re: mappedBy reference an unknown target entity property
PostPosted: Mon Aug 10, 2009 7:32 am 
Expert
Expert

Joined: Tue May 13, 2008 3:42 pm
Posts: 919
Location: Toronto & Ajax Ontario www.hibernatemadeeasy.com
Do you have a mapping for the items class in your hibernate configuration mapping file? Problably, it's the addition of the Item.class to the config object when Hibernate is initialized. Maybe it's spelled incorrectly?

_________________
Cameron McKenzie - Author of "Hibernate Made Easy" and "What is WebSphere?"
http://www.TheBookOnHibernate.com Check out my 'easy to follow' Hibernate & JPA Tutorials


Top
 Profile  
 
 Post subject: Re: mappedBy reference an unknown target entity property
PostPosted: Mon Aug 10, 2009 7:54 am 
Expert
Expert

Joined: Fri Jul 13, 2007 8:18 am
Posts: 370
Location: london
You're mappedBy suggests company is in the Item class but in actuality its in the ItemPk class. So, try this instead:
Code:
@OneToMany(mappedBy = "itemPK.company")
private Set<Item> items;


Top
 Profile  
 
 Post subject: Re: mappedBy reference an unknown target entity property
PostPosted: Mon Aug 10, 2009 8:12 am 
Newbie

Joined: Sun Aug 09, 2009 12:14 pm
Posts: 16
It works !!!
Thank You Very much


Top
 Profile  
 
 Post subject: Re: mappedBy reference an unknown target entity property
PostPosted: Tue Aug 11, 2009 10:22 am 
Newbie

Joined: Sun Aug 09, 2009 12:14 pm
Posts: 16
I have another question refers to this code.
Now my ItemPK is the @Embeddable class of Item.class and i try to connect to ItemCrossReference.Class

@Entity
public class ItemCrossReference {

@EmbeddedId
public ItemCrossReferencePK itemCrossReferencePK;

@ManyToOne
@JoinColumns( {
@JoinColumn(name = "REF_MANUF_CMP_CODE", referencedColumnName = "ITM_COMP_ID"),
@JoinColumn(name = "REF_MANUF_REF_CODE", referencedColumnName = "ITM_ITEM_CODE") })
protected Item manufItem;
}

@Entity
public class Item implements Serializable{
private static final long serialVersionUID = 8635086262992868784L;

@EmbeddedId
public ItemPK itemPK;

//Setter and getter ...
}

@Embeddable
public class ItemPK implements Serializable {

private static final long serialVersionUID = -5177491823551943094L;

@ManyToOne
@JoinColumn(name="ITM_COMP_ID", referencedColumnName="CMP_COMPANY_ID")
protected Company company;

public Company getCompany() {
return company;
}

@OneToMany(mappedBy="itemCrossReference.itemPK")
private Set<ItemCrossReference> itemCrossReferences;

public void setCompany(Company company) {
this.company = company;
}

@Column(name="ITM_ITEM_CODE", nullable=false)
private String itemCode;

public String getItemCode() {
return itemCode;
}

public void setItemCode(String itemCode) {
this.itemCode = itemCode;
}

public void setItemCrossReferences(Set<ItemCrossReference> itemCrossReferences) {
this.itemCrossReferences = itemCrossReferences;
}

public Set<ItemCrossReference> getItemCrossReferences() {
return itemCrossReferences;
}

public boolean equals(Object other) {
if (other instanceof ItemPK) {
final ItemPK otherItemPK = (ItemPK) other;
return (otherItemPK.company.equals(company) && otherItemPK.itemCode.equals(itemCode));
}
return false;
}

public int hashCode() {
return super.hashCode();
}
}

The error now is:
mappedBy reference an unknown target entity property: model.ItemCrossReference.itemCrossReference.itemPK in model.Item.itemCrossReferences

This is very confusing, what is wrong with this one ?


Top
 Profile  
 
 Post subject: Re: mappedBy reference an unknown target entity property
PostPosted: Tue Mar 30, 2010 9:35 am 
Newbie

Joined: Tue Mar 30, 2010 9:06 am
Posts: 1
Nice one. But how about when using @IdClass instead of @EmbeddedId?

thatmikewilliams wrote:
You're mappedBy suggests company is in the Item class but in actuality its in the ItemPk class. So, try this instead:
Code:
@OneToMany(mappedBy = "itemPK.company")
private Set<Item> items;


Top
 Profile  
 
 Post subject: Re: mappedBy reference an unknown target entity property
PostPosted: Wed Feb 23, 2011 7:24 pm 
Newbie

Joined: Wed Feb 23, 2011 7:10 pm
Posts: 1
I solve the problem 'mappedBy reference an unknown target entity property:' with this way.

public class C implements Serializable {

@OneToMany(mappedBy = "usedby2") // this mappedBy is the same name of field in the class Cc
private List<Object> usedby2;
}

public class Cc implements Serializable {
@JoinColumn(name = "USEDBY2", referencedColumnName = "ID", nullable = false, insertable = false, updatable = false)
@ManyToOne(optional = false)
private Object usedby2; // this field name is the same mappedBy in the class Cc
}

public class CircuitcircuitPK implements Serializable {
@Basic(optional = false)
@Column(name = "USEDBY2", nullable = false)
private BigInteger usedby2;

}

I hope help you, too late i know.


Top
 Profile  
 
 Post subject: Re: mappedBy reference an unknown target entity property
PostPosted: Fri Jul 15, 2011 8:42 am 
Newbie

Joined: Fri Jul 15, 2011 8:38 am
Posts: 1
I solved that problem.
Please check getter setter method names.It should be of your mapped by name
e.g If you are mapped by department then your getter & setter method name must be getDepartment() and setDepartment()


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