Long story short, I need to convert a bytea from PostgreSQL to an int[][] using Java 6 (or SQL.)
If you want context, feel free to read below, but that's really all there is to it.
Context
Somebody who used to work in the team I am in wrote a bean like this:
public class FourPointBean {
@Column(name = "points", length = "65535")
private int[][] xy;
... other irrelevant stuff
}
Where the int[][] was really just four points (no idea why he chose an int[][]...)
(xy[0][0], xy[0][1]) := (x0, y0)
(xy[1][0], xy[1][1]) := (x1, y1)
(xy[2][0], xy[2][1]) := (x2, y2)
(xy[3][0], xy[3][1]) := (x3, y3)
And apparently for years Hibernate had been throwing an exception that everybody ignored because it was "only a warning" --
WARNING: duplicate class definition bug occured? Please report this :
com/company/blah/SomeBean$JaxbAccessorM_getXy_setXy_Array_Of_[I
java.lang.ClassFormatError: Illegal class name
"com/company/blah/SomeBean$JaxbAccessorM_getXy_setXy_Array_Of_[I" in class file
com/company/blah/SomeBean$JaxbAccessorM_getXy_setXy_Array_Of_[I
at java.lang.ClassLoader.defineClass1(Native Method)
...
The result was Hibernate inserting the int array as a byta in the table. Eventually this bean definition actually caused some issues, so I changed it --
public class FourPointBean {
@Type(type = "com.company.blah.PointArrayType")
@Column(name = "points", length = 65535, columnDefinition = "int[][]")
private int[][] xy;
... other irrelevant stuff
}
And then I changed the DTO used by the UI to:
public class FourPointDTO {
private List<Point> points = Lists.newArrayListWithCapacity(4);
...
}
Which is all fine and dandy, but now I have to write something to migrate all of the messy existing byte arrays in the table in question to a PostgreSQL int[]... using Java 6.
Everything I saw online was involving 1D-arrays that did not translate cleanly... right now I can't even figure out how to turn int[][] into a byte array for testing purposes.
As always, help is much appreciated...
Edit
Here are a couple translations --
(00525bc5f039-2d70-40f0-922c-0ef7060816be
)
int[][]
[0][0] := 538
[0][1] := 760
[1][0] := 676
[1][1] := 760
[2][0] := 676
[2][1] := 890
[3][0] := 538
[3][1] := 890
Bytes
\xaced0005757200035b5b4917f7e44f198f893c020000787000000004757200025b494dba602676eab2a50200007870000000020000021a000002f87571007e000200000002000002a4000002f87571007e000200000002000002a40000037a7571007e0002000000020000021a0000037a
(005276c1cb74-2476-43bf-856e-43912e969000
)
int[][]
[0][0] := 544
[0][1] := 638
[1][0] := 657
[1][1] := 638
[2][0] := 657
[2][1] := 743
[3][0] := 544
[3][1] := 743
Bytes
\xaced0005757200035b5b4917f7e44f198f893c020000787000000004757200025b494dba602676eab2a5020000787000000002000002200000027e7571007e000200000002000002910000027e7571007e00020000000200000291000002e77571007e00020000000200000220000002e7