0

I've got a DB in which I've changed the types of a few columns. When I'm trying to run my Spring-boot app that is supposed to connect to that same DB, I'm getting the following error:

Schema-validation: wrong column type encountered in column [area] in table [hero]; found [polygon (Types#OTHER)], but expecting [bytea (Types#VARBINARY)]

I've double-checked my table and the type of said column is clearly polygon, I've no idea why it expects a different type, here are the relevant files:

application.properties:

spring.datasource.url=jdbc:postgresql://localhost:5432/herodb
spring.datasource.username=postgres
spring.datasource.password=123
spring.jpa.hibernate.ddl-auto=validate
spring.datasource.driver-class-name=org.postgresql.Driver
spring.jpa.properties.hibernate.jdbc.lob.non_contextual_creation=true

Hero entity class:

package com.db.entities;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
import com.db.DBApp;
import org.hibernate.annotations.Type;
import org.postgresql.geometric.PGpoint;
import org.postgresql.geometric.PGpolygon;

@Entity
@Table(name="hero")
public class Hero
{

    public int getHid() {
        return hid;
    }

    public PGpolygon getArea() {
        return area;
    }

    public String getSpower() {
        return spower;
    }

    public String getFname() {
        return fname;
    }

    public String getLname() {
        return lname;
    }

    public DBApp.PowerCatagory getPc() {
        return pc;
    }

    public float getPower_level() {
        return power_level;
    }

    public float getLuck() {
        return luck;
    }

    public void setHid(int hid) {
        this.hid = hid;
    }

    public void setArea(PGpolygon area) {
        this.area = area;
    }

    public void setSpower(String spower) {
        this.spower = spower;
    }

    public void setFname(String fname) {
        this.fname = fname;
    }

    public void setLname(String lname) {
        this.lname = lname;
    }

    public void setPc(DBApp.PowerCatagory pc) {
        this.pc = pc;
    }

    public void setPower_level(float power_level) {
        this.power_level = power_level;
    }

    public void setLuck(float luck) {
        this.luck = luck;
    }

    @Id private int hid;//This is the table's primary key
    private String fname;
    private String lname;
    private float luck;
    private float power_level;
    private String spower;
    private DBApp.PowerCatagory pc;
    private PGpolygon area;


    public Hero(int hid, String fname, String lname, float luck,float power_level,String spower,DBApp.PowerCatagory pc,PGpolygon area) {
        this.hid = hid;
        this.area = area;
        this.spower = spower;
        this.fname = fname;
        this.lname = lname;
        this.pc = pc;
        this.power_level = power_level;
        this.luck = luck;
    }

    public Hero()
    {

    }

}

pom.xml file:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>MyDBExcercise</groupId>
    <artifactId>mydbexxcercise</artifactId>
    <version>1.0-SNAPSHOT</version>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-parent</artifactId>
        <version>2.1.4.RELEASE</version>
    </parent>

    <dependencies>
        <dependency>
            <groupId>com.aerospike</groupId>
            <artifactId>spring-data-aerospike</artifactId>
            <version>2.0.1.RELEASE</version>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>

        <dependency>
            <groupId>org.postgresql</groupId>
            <artifactId>postgresql</artifactId>
        </dependency>


    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>


</project>

Thank you in advance!

BitThinker483
  • 25
  • 1
  • 5
  • `area` and `pc` fields are not standard java types. Those are classes you implemented yourself. You can't map them like that to just 1 database column. You need to use `@OneToOne` or anything alike – XtremeBaumer May 16 '19 at 08:46
  • @XtremeBaumer they're mapped to 2 different columns – BitThinker483 May 16 '19 at 08:52
  • Doesnt matter. They need to me mapped to another table. I doubt that you store all the information for `PGpolygon` in just 1 column. You are very probably just storing the reference there – XtremeBaumer May 16 '19 at 08:54
  • @XtremeBaumer I'm sorry but I don't follow you, why do they need to be mapped to a different table? I've got one column in my table that is of type polygon, and after checking online the class that can be mapped to such a column in Java is PGpolygon – BitThinker483 May 16 '19 at 09:00
  • Alright, I see where you coming from. My bad here. Can you provide the hibernate dialect you use? It looks like you also need `org.hibernate.spatial` – XtremeBaumer May 16 '19 at 09:05
  • @XtremeBaumer sorry again, I've no idea what is hibernate dialect, I'm pretty sure such a thing isn't present in my code, I've provided my application.properties file though. – BitThinker483 May 16 '19 at 09:09
  • [This](https://stackoverflow.com/questions/16572039/connecting-postgresql-9-2-1-with-hibernate) and [this](https://examples.javacodegeeks.com/enterprise-java/hibernate/hibernate-eclipse-postgresql-example/) should give you an insight on how to configure hibernate to run with PostgreSQL. It will not solve your problem at hand, but might erase future problems – XtremeBaumer May 16 '19 at 09:16

0 Answers0