-->
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: Use of @OneToMany or @ManyToMany targeting an unmapped class
PostPosted: Wed Dec 04, 2013 8:18 pm 
Newbie

Joined: Wed Dec 04, 2013 8:05 pm
Posts: 1
Hi, I'm using JPA Hibernate with Java and get following error: ( I think its about wrong annotiation of a valueobject...)

Caused by: org.hibernate.AnnotationException: Use of @OneToMany or @ManyToMany targeting an unmapped class: be.wijnhuis.entities.BestelBon.bestelbonlijnen[be.wijnhuis.valueobjects.BestelBonLijn]

In the package 'be.wijnhuis.valueobjects' I have the following class:

package be.wijnhuis.valueobjects;

import java.io.Serializable;

import javax.persistence.Embeddable;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;

import be.wijnhuis.entities.BestelBon;
import be.wijnhuis.entities.Wijn;

@Embeddable
public class BestelBonLijn implements Serializable {
private static final long serialVersionUID = 1L;

private long bonNr;
private long wijnNr;
private long aantal;

@ManyToOne(fetch=FetchType.LAZY)
@JoinColumn(name="BonNr")
private BestelBon bestelBon;

@ManyToOne(fetch=FetchType.LAZY)
@JoinColumn(name="WijnNr")
private Wijn wijn;

public BestelBonLijn() {
}

public BestelBonLijn(long bonNr, long wijnNr, long aantal) {
this.bonNr = bonNr;
this.wijnNr = wijnNr;
this.aantal = aantal;
}

public long getAantal() {
return aantal;
}

public void setAantal(long aantal) {
this.aantal = aantal;
}

public BestelBon getBestelBon() {
return bestelBon;
}

public void setBestelBon(BestelBon bestelBon) {
this.bestelBon = bestelBon;
}

public Wijn getWijn() {
return wijn;
}

public void setWijn(Wijn wijn) {
this.wijn = wijn;
}

@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + (int) (bonNr ^ (bonNr >>> 32));
result = prime * result + (int) (wijnNr ^ (wijnNr >>> 32));
return result;
}

@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
BestelBonLijn other = (BestelBonLijn) obj;
if (bonNr != other.bonNr)
return false;
if (wijnNr != other.wijnNr)
return false;
return true;
}
}

------------------------------------

package be.wijnhuis.entities;

import java.io.Serializable;
import java.util.Collections;
import java.util.Date;
import java.util.LinkedHashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Embedded;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

import be.wijnhuis.enums.Bestelwijze;
import be.wijnhuis.valueobjects.Adres;
import be.wijnhuis.valueobjects.BestelBonLijn;

@Entity
@Table(name = "bestelbonnen")
public class BestelBon implements Serializable {
private static final long serialVersionUID = 1L;

@Id
@GeneratedValue
private long bonNr;

@Temporal(TemporalType.TIMESTAMP)
private Date bestelDatum;

private String naam;

@Embedded
private Adres adres;

private Bestelwijze bestelwijze;


// @ElementCollection
// @CollectionTable(
// name="bestelbonlijnen",
// joinColumns = @JoinColumn(name="BonNr")
// )
// @Embedded
@OneToMany(mappedBy="bestelBon", cascade=CascadeType.PERSIST)
private Set<BestelBonLijn>bestelbonlijnen;

public BestelBon() {
this.bestelbonlijnen = new LinkedHashSet<>();
}

public BestelBon(Date bestelDatum, String naam, Adres adres,
Bestelwijze bestelwijze) {
setBestelDatum(bestelDatum);
this.naam = naam;
this.adres = adres;
this.bestelwijze = bestelwijze;
this.bestelbonlijnen = new LinkedHashSet<>();
}

public long getBonNr() {
return bonNr;
}

public Date getBestelDatum() {
return (Date) bestelDatum.clone();
}

public void setBestelDatum(Date bestelDatum) {
this.bestelDatum = (Date) bestelDatum.clone();
}

public String getNaam() {
return naam;
}

public void setNaam(String naam) {
this.naam = naam;
}

public Adres getAdres() {
return adres;
}

public void setAdres(Adres adres) {
this.adres = adres;
}

public Bestelwijze getBestelwijze() {
return bestelwijze;
}

public void setBestelwijze(Bestelwijze bestelwijze) {
this.bestelwijze = bestelwijze;
}

public Set<BestelBonLijn> getBestelbonlijnen() {
return Collections.unmodifiableSet(bestelbonlijnen);
}

public void addBestelBonLijn(BestelBonLijn bestelbonlijn){
bestelbonlijnen.add(bestelbonlijn);
if(bestelbonlijn.getBestelBon() != this){
bestelbonlijn.setBestelBon(this);
}
}

@Override
public String toString() {
return "BestelBon [bonNr=" + bonNr + ", bestelDatum=" + bestelDatum
+ ", naam=" + naam + ", adres=" + adres + ", bestelwijze="
+ bestelwijze + "]";
}

}
-------------------------
Thanks for your help


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.