Skip to content
Advertisement

Spring-Boot When running .JAR of project it fails to initialize JPA

What I want to achieve is that when I push something to my staging branch on github a script on the Ubuntu server automatically pulls the branch, compiles the project and runs the .JAR file.

But I’m facing a problem where if I package my project on Ubuntu it fails to initialize JPA EntityManagerFactory. It gives the following exception: “Failed to initialize JPA EntityManagerFactory: Unable to find column with logical name category in table hardware”

Whenever I run the project on Ubuntu with the “mvn spring-boot:run” command it runs fine without any problem. Also when I compile the project on Windows the .JAR file runs fine too. I made sure I use the same versions of the JDK and Maven on Ubuntu and my Windows PC. The dependency versions are also the same. When I run the .JAR file I made on my Windows PC on Ubuntu it runs fine too. I have no clue what the issue could be.

HardwareEntity.java

@Entity
@Table(name = "hardware")
public class HardwareEntity {
    @Id
    private String sku;
    @Column(length = 55)
    private String size;
    @Column(length = 55)
    private String type;
    @Column(length = 55)
    private String control;
    private String color;
    private String status;
    private Integer delivery_time;
    @ManyToOne
    @JoinColumn(name = "category")
    private CategoryEntity category;

    // Getters & Setters
} 

CategoryEntity.java

@Entity
@Table(name = "category")
public class CategoryEntity {
    @Id
    @Column(length = 55)
    private String code;
    private String description;
    @OneToMany(mappedBy = "category")
    private List<SoftwareEntity> families;
    @OneToMany(mappedBy = "category")
    private List<HardwareEntity> hardwares;
    
    // Getters & Setters
}

Advertisement

Answer

I fixed it by creating an image of an Ubuntu system where everything did work as expected and then use that image on the server. I still don’t know what the exact issue was but it’s fixed.

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement