Org.Hibernate.Annotationexception: @Onetoone or @Manytoone on <Entity> References an Unknown Entity

org.hibernate.AnnotationException: @OneToOne or @ManyToOne on entities.Ques#tion.examId references an unknown entity: long

If you look closely at your stacktrace, you will see

Caused by: org.hibernate.AnnotationException: @OneToOne or @ManyToOne on entities.Question.examId references an unknown entity: long

So this field

@ManyToOne
private long examId;

is causing the problem. @ManyToOne has a paramater targetEntity which says:

(Optional) The entity class that is the target of the association.
Defaults to the type of the field or property that stores the association.

Since you haven't provided that parameter, it defaults to long, which is not a managed Entity.

You'll probably want to use

@ManyToOne(targetEntity = Exam.class)
private long examId;

otherwise it won't know what to map to. Or even better

@ManyToOne
private Exam exam;

@OneToOne or @ManyToOne on references an unknown entity

Well, it's because you tell the factoryBean that your entities are in the factoryBean.setPackagesToScan(ParcoursupDAOConfig.class.getPackage().getName()); package, which is nc.unc.importparcoursup.dao.admisDAO. and PreCandidat is in the nc.unc.importparcoursup.dao.pgiCocktailDAO.entity package...

Try factoryBean.setPackagesToScan("nc.unc.importparcoursup.dao") or move your class config to a higher level.

Caused by: org.hibernate.AnnotationException: @OneToOne or @ManyToOne on

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name="kode_korwil", nullable=false)
public Korwil getKode_korwil() { //return type must be Korwil not String
return kode_korwil;
}

and I think

@Id
@JoinColumn(name="no_dana") //Column instead JoinColumn ??
public String getNo_dana() {
return no_dana;
}

Also remove one of the @Id annotation because you have 2 Id annotation, each entity should have only one Id

@Id  <--------------------------------- remove one of @ID annotation.
@Column(name="kode_korwil", unique=true, nullable=false)
public String getKode_korwil() {
return kode_korwil;
}

@Id <--------------------------------- remove one of @ID annotation.
@JoinColumn(name="no_dana")
public String getNo_dana() {
return no_dana;
}

Hibernate @ManyToOne references an unknown entity

I figured out the problem: I was not adding class Team to the Hibernate AnnotationConfiguration object. Thus, Hibernate was not recognizing the class.

org.hibernate.AnnotationException: @OneToOne or @ManyToOne

In class Order import @entity from javax.persistence instead of org.hibernate.annotations.Entity

Spring Boot Error: @OneToOne or @ManyToOne references an unknown entity

As the error suggests, you are annotating (referencing) a non-persistent type within anohter JPA Entity.

The EarthquakeEntity should be the mapped type instead of EarthquakeDto:

@Entity(name = "distances")
public class DistancesEntity implements Serializable {

// other fields

@ManyToOne(fetch = FetchType.LAZY, optional = false)
@JoinColumn(name = "earthquakes_id", nullable = false)
private EarthquakeEntity earthquakeDetails;

// getters and setters
}

You should then configure your ModelMapper so that the DistanceDto gets automatically mapped to DistanceEntity as well when mapping the EarthquakeDto to a EarthquakeEntity instance.

Note that you issue has nothing to do with the Spring framework itself and is a pure JPA - Hibernate error.



Related Topics



Leave a reply



Submit