'Java spring boot data entity
I am working on java spring boot application with spring tool suite and I follow a certain tutorial for entity mapping but am getting an error that says unknown entity of a thing. Here is the error from the console. I will really appreciate everyone's suggestions.
```
Caused by: org.hibernate.AnnotationException: @OneToOne or @ManyToOne on com.elijahukeme.PropertiesManagementSystem.model.Vehicle.inCharge references an unknown entity: com.elijahukeme.PropertiesManagementSystem.model.Employee at org.hibernate.cfg.ToOneFkSecondPass.doSecondPass(ToOneFkSecondPass.java:100) ~[hibernate-core-5.6.4.Final.jar:5.6.4.Final] at org.hibernate.boot.internal.InFlightMetadataCollectorImpl.processEndOfQueue(InFlightMetadataCollectorImpl.java:1750) ~[hibernate-core-5.6.4.Final.jar:5.6.4.Final] at org.hibernate.boot.internal.InFlightMetadataCollectorImpl.processFkSecondPassesInOrder(InFlightMetadataCollectorImpl.java:1694) ~[hibernate-core-5.6.4.Final.jar:5.6.4.Final] at org.hibernate.boot.internal.InFlightMetadataCollectorImpl.processSecondPasses(InFlightMetadataCollectorImpl.java:1623) ~[hibernate-core-5.6.4.Final.jar:5.6.4.Final] at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.complete(MetadataBuildingProcess.java:295) ~[hibernate-core-5.6.4.Final.jar:5.6.4.Final] at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.metadata(EntityManagerFactoryBuilderImpl.java:1460) ~[hibernate-core-5.6.4.Final.jar:5.6.4.Final] at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:1494) ~[hibernate-core-5.6.4.Final.jar:5.6.4.Final] at org.springframework.orm.jpa.vendor.SpringHibernateJpaPersistenceProvider.createContainerEntityManagerFactory(SpringHibernateJpaPersistenceProvider.java:58) ~[spring-orm-5.3.15.jar:5.3.15] at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:365) ~[spring-orm-5.3.15.jar:5.3.15] at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.buildNativeEntityManagerFactory(AbstractEntityManagerFactoryBean.java:409) ~[spring-orm-5.3.15.jar:5.3.15] at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:396) ~[spring-orm-5.3.15.jar:5.3.15] at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.afterPropertiesSet(LocalContainerEntityManagerFactoryBean.java:341) ~[spring-orm-5.3.15.jar:5.3.15] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1863) ~[spring-beans-5.3.15.jar:5.3.15] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1800) ~[spring-beans-5.3.15.jar:5.3.15] ... 16 common frames omitted ```
Here is my Employee class
package com.elijahukeme.PropertiesManagementSystem.model;
import com.fasterxml.jackson.annotation.JsonIdentityInfo;
import com.fasterxml.jackson.annotation.ObjectIdGenerators;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.springframework.format.annotation.DateTimeFormat;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.MappedSuperclass;
import java.util.Date;
@Entity
@Data
@EqualsAndHashCode(callSuper=false)
@MappedSuperclass
@JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property = "id")
public class Employee extends Person{
@ManyToOne
@JoinColumn(name="employeetypeid", insertable=false, updatable=false)
private EmployeeType employeeType;
private Integer employeetypeid;
private String photo;
private String username;
@ManyToOne
@JoinColumn(name="jobtitleid", insertable=false, updatable=false)
private JobTitle jobTitle;
private Integer jobtitleid;
@DateTimeFormat(pattern = "yyyy-MM-dd")
private Date hireDate;
}
```
And here is my Vehicle class
```java
package com.elijahukeme.PropertiesManagementSystem.model;
import com.fasterxml.jackson.annotation.JsonIdentityInfo;
import com.fasterxml.jackson.annotation.ObjectIdGenerators;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.format.annotation.DateTimeFormat;
import javax.persistence.*;
import java.util.Date;
@Entity
@Data
@NoArgsConstructor
@AllArgsConstructor
@JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property = "id")
public class Vehicle {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name="id")
private int id;
private String name;
@ManyToOne
@JoinColumn(name="vehicletypeid", insertable=false, updatable=false)
private VehicleType vehicleType;
private Integer vehicletypeid;
private String vehicleNumber;
@DateTimeFormat(pattern = "yyyy-MM-dd")
private Date registrationDate;
@DateTimeFormat(pattern = "yyyy-MM-dd")
private Date acquisitionDate;
private String description;
@ManyToOne
@JoinColumn(name="vehiclemakeid", insertable=false, updatable=false)
private VehicleMake vehicleMake;
private Integer vehiclemakeid;
private String power;
private String fuelCapacity;
@ManyToOne
@JoinColumn(name="vehiclestatusid", insertable=false, updatable=false)
private VehicleStatus vehicleStatus;
private Integer vehiclestatusid;
private String netWeight;
@ManyToOne
@JoinColumn(name="employeeid", insertable=false, updatable=false)
private Employee inCharge;
private Integer employeeid;
@ManyToOne
@JoinColumn(name="vehiclemodelid", insertable=false, updatable=false)
private VehicleModel vehicleModel;
private Integer vehiclemodelid;
@ManyToOne
@JoinColumn(name="locationid", insertable=false, updatable=false)
private Location currentLocation;
private Integer locationid;
private String remarks;
}
Employee class
package com.elijahukeme.PropertiesManagementSystem.model;
import com.fasterxml.jackson.annotation.JsonIdentityInfo;
import com.fasterxml.jackson.annotation.ObjectIdGenerators;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.springframework.format.annotation.DateTimeFormat;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.MappedSuperclass;
import java.util.Date;
@Entity
@Data
@EqualsAndHashCode(callSuper=false)
@MappedSuperclass
@JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property = "id")
public class Employee extends Person{
@ManyToOne
@JoinColumn(name="employeetypeid", insertable=false, updatable=false)
private EmployeeType employeeType;
private Integer employeetypeid;
private String photo;
private String username;
@ManyToOne
@JoinColumn(name="jobtitleid", insertable=false, updatable=false)
private JobTitle jobTitle;
private Integer jobtitleid;
@DateTimeFormat(pattern = "yyyy-MM-dd")
private Date hireDate;
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|