0

i want to design a column is text type and use hibernate to convert to object but the column is a bit difficult,it is liked "1.5,2.32;4.2,53.2...." it represent many coordinate and is in order,(1.5,2.32),(4.2,53.2) and so on. so i want to mappting the column to an object like

Public class Region{
  List<Coordinate> coordinateList;
}

public class Coordinate {
 double lat;
 double lng;
}

the coordinateList is the same as the column order such as (1.5,2.32),(4.2,53.2) so how can i use annotion jpa or hibnernate annotation to convert the column to my defined object?

王奕然
  • 3,891
  • 6
  • 41
  • 62
  • possible duplicate of [how to serialize and deserialize hibernate object?](http://stackoverflow.com/questions/13068663/how-to-serialize-and-deserialize-hibernate-object) – danizmax Sep 30 '14 at 06:22
  • Without using only one column, what is your problem if you define `Region` & `Coordinate` as Entity and do appropriate relationship from main/parent Entity ??? It will make your life easier for future manage & maintain on them. – Wundwin Born Sep 30 '14 at 06:25
  • but how can i get the order of many coordinate? – 王奕然 Sep 30 '14 at 06:26

1 Answers1

0

Check this SO question. You need to implement a Hibernate UserType, which converts a specific SQL value to a custom Java type.

You could implement a similar SetStringType UserType, splitting string coordinates by comma and constructing Coordinate Java objects.

Community
  • 1
  • 1
Vlad Mihalcea
  • 142,745
  • 71
  • 566
  • 911