Which Polygon classes hibernate can accept?

Viewed 91

I have a Spring project and I'am trying to create a Polygon Object in Java that Hibernate can handle but I have seen that it exists in Java many class to create a Polygon Object like "org.geojson.Polygon", "com.vividsolutions.jts.geom.Polygon" or "org.springframework.data.geo.Polygon". How can I know which of this classes Hibernate accepts ?

My class :



@Entity  public class Area implements Serializable {     

private static final long serialVersionUID = 1L;

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long idArea;


@Column( columnDefinition = "Polygon" )
private Polygon coordinates;    // What imports to do for this Polygon attribute?


@Column(unique = true)
private String name; 
}

// Constructors and getters/setters ...

Thanks for any help !

1 Answers

Out of the box Hibernate-core only supports a relatively limited number of types, if you want to use complex types such as Polygon you'll need to either map them yourself (implementing org.hibernate.UserType or org.hibernate.CompositeUserType) or use a library that does it for you.

For spatial data there's the hibernate-spatial, you'll find an introduction here but essentially you'll need to add the dependency:

<dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-spatial</artifactId>
    <version>${hibernate.version}</version>
</dependency>
Related