exception: "Can't infer the SQL type "

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

exception: "Can't infer the SQL type "

orkun
Hello


I want to store a POINT in postgis db
I am never able to solve this problem.


  String wktPoint="POINT(10 5)";
        Geometry geom = wktToGeometry(wktPoint);

        String INSERT_SQL="INSERT INTO memberhibernate4demo
(id,location) values (2,?)";
        em.createNativeQuery(INSERT_SQL).setParameter(1,geom).executeUpdate();


21:13:42,621 INFO  [stdout] (http--127.0.0.1-8080-1) Hibernate:
21:13:42,621 INFO  [stdout] (http--127.0.0.1-8080-1)     INSERT
21:13:42,622 INFO  [stdout] (http--127.0.0.1-8080-1)     INTO
21:13:42,622 INFO  [stdout] (http--127.0.0.1-8080-1)
memberhibernate4demo
21:13:42,622 INFO  [stdout] (http--127.0.0.1-8080-1)         (id,location)
21:13:42,622 INFO  [stdout] (http--127.0.0.1-8080-1)     values
21:13:42,622 INFO  [stdout] (http--127.0.0.1-8080-1)         (2,?)
21:13:42,630 WARN  [org.hibernate.engine.jdbc.spi.SqlExceptionHelper]
(http--127.0.0.1-8080-1) SQL Error: 0, SQLState: 07006
21:13:42,630 ERROR [org.hibernate.engine.jdbc.spi.SqlExceptionHelper]
(http--127.0.0.1-8080-1) Can't infer the SQL type to use for an
instance of org.postgis.PGgeometry. Use setObject() with an explicit
Types value to specify the type to use.

---

what am I doing wrong ?

regards



--
Ahmet Temiz
Jeoloji Müh.
Afet ve Acil Durum Yönetimi Başkanlığı
Planlama ve Zarar Azaltma Dairesi Başkanlığı

Eskişehir Yolu 10. km.
Lodumlu / Ankara
Tel : 0 312 2872680 / 1535
________________________

Ahmet Temiz
Geological Eng.
Information Systems - GIS Group
Disaster and Emergency Management
of Presidency
_______________________________________________
hibernatespatial-users mailing list
[hidden email]
http://www.hibernatespatial.org/cgi-bin/mailman/listinfo/hibernatespatial-users
Reply | Threaded
Open this post in threaded view
|

Re: exception: "Can't infer the SQL type "

klaus.rossmy
Use the setParameter(int position, Object val, Type type) method with org.hibernate.spatial.GeometryType as Type

hth
Tilman
-----Original Message-----
From: [hidden email] [mailto:[hidden email]] On Behalf Of Ahmet Temiz
Sent: Freitag, 16. November 2012 20:20
To: Hibernate Spatial Users Discussion
Subject: [hibernatespatial-users] exception: "Can't infer the SQL type "

Hello


I want to store a POINT in postgis db
I am never able to solve this problem.


  String wktPoint="POINT(10 5)";
        Geometry geom = wktToGeometry(wktPoint);

        String INSERT_SQL="INSERT INTO memberhibernate4demo
(id,location) values (2,?)";
        em.createNativeQuery(INSERT_SQL).setParameter(1,geom).executeUpdate();


21:13:42,621 INFO  [stdout] (http--127.0.0.1-8080-1) Hibernate:
21:13:42,621 INFO  [stdout] (http--127.0.0.1-8080-1)     INSERT
21:13:42,622 INFO  [stdout] (http--127.0.0.1-8080-1)     INTO
21:13:42,622 INFO  [stdout] (http--127.0.0.1-8080-1)
memberhibernate4demo
21:13:42,622 INFO  [stdout] (http--127.0.0.1-8080-1)         (id,location)
21:13:42,622 INFO  [stdout] (http--127.0.0.1-8080-1)     values
21:13:42,622 INFO  [stdout] (http--127.0.0.1-8080-1)         (2,?)
21:13:42,630 WARN  [org.hibernate.engine.jdbc.spi.SqlExceptionHelper]
(http--127.0.0.1-8080-1) SQL Error: 0, SQLState: 07006
21:13:42,630 ERROR [org.hibernate.engine.jdbc.spi.SqlExceptionHelper]
(http--127.0.0.1-8080-1) Can't infer the SQL type to use for an
instance of org.postgis.PGgeometry. Use setObject() with an explicit
Types value to specify the type to use.

---

what am I doing wrong ?

regards



--
Ahmet Temiz
Jeoloji Müh.
Afet ve Acil Durum Yönetimi Başkanlığı
Planlama ve Zarar Azaltma Dairesi Başkanlığı

Eskişehir Yolu 10. km.
Lodumlu / Ankara
Tel : 0 312 2872680 / 1535
________________________

Ahmet Temiz
Geological Eng.
Information Systems - GIS Group
Disaster and Emergency Management
of Presidency
_______________________________________________
hibernatespatial-users mailing list
[hidden email]
http://www.hibernatespatial.org/cgi-bin/mailman/listinfo/hibernatespatial-users
_______________________________________________
hibernatespatial-users mailing list
[hidden email]
http://www.hibernatespatial.org/cgi-bin/mailman/listinfo/hibernatespatial-users
Reply | Threaded
Open this post in threaded view
|

Re: exception: "Can't infer the SQL type "

Jan Boonen
In reply to this post by orkun
Hi Ahmet,

Could please post your entity mapping (either annotations of xml file)
to the list. I think that there may be an error in your mapping.

Cheers,

Jan

On 16-11-2012 20:20, Ahmet Temiz wrote:

> Hello
>
>
> I want to store a POINT in postgis db
> I am never able to solve this problem.
>
>
>    String wktPoint="POINT(10 5)";
>          Geometry geom = wktToGeometry(wktPoint);
>
>          String INSERT_SQL="INSERT INTO memberhibernate4demo
> (id,location) values (2,?)";
>          em.createNativeQuery(INSERT_SQL).setParameter(1,geom).executeUpdate();
>
>
> 21:13:42,621 INFO  [stdout] (http--127.0.0.1-8080-1) Hibernate:
> 21:13:42,621 INFO  [stdout] (http--127.0.0.1-8080-1)     INSERT
> 21:13:42,622 INFO  [stdout] (http--127.0.0.1-8080-1)     INTO
> 21:13:42,622 INFO  [stdout] (http--127.0.0.1-8080-1)
> memberhibernate4demo
> 21:13:42,622 INFO  [stdout] (http--127.0.0.1-8080-1)         (id,location)
> 21:13:42,622 INFO  [stdout] (http--127.0.0.1-8080-1)     values
> 21:13:42,622 INFO  [stdout] (http--127.0.0.1-8080-1)         (2,?)
> 21:13:42,630 WARN  [org.hibernate.engine.jdbc.spi.SqlExceptionHelper]
> (http--127.0.0.1-8080-1) SQL Error: 0, SQLState: 07006
> 21:13:42,630 ERROR [org.hibernate.engine.jdbc.spi.SqlExceptionHelper]
> (http--127.0.0.1-8080-1) Can't infer the SQL type to use for an
> instance of org.postgis.PGgeometry. Use setObject() with an explicit
> Types value to specify the type to use.
>
> ---
>
> what am I doing wrong ?
>
> regards
>
>
>
> --
> Ahmet Temiz
> Jeoloji Müh.
> Afet ve Acil Durum Yönetimi Başkanlığı
> Planlama ve Zarar Azaltma Dairesi Başkanlığı
>
> Eskişehir Yolu 10. km.
> Lodumlu / Ankara
> Tel : 0 312 2872680 / 1535
> ________________________
>
> Ahmet Temiz
> Geological Eng.
> Information Systems - GIS Group
> Disaster and Emergency Management
> of Presidency
> _______________________________________________
> hibernatespatial-users mailing list
> [hidden email]
> http://www.hibernatespatial.org/cgi-bin/mailman/listinfo/hibernatespatial-users


_______________________________________________
hibernatespatial-users mailing list
[hidden email]
http://www.hibernatespatial.org/cgi-bin/mailman/listinfo/hibernatespatial-users
Reply | Threaded
Open this post in threaded view
|

Re: exception: "Can't infer the SQL type "

orkun
here is the my entity class


import java.io.Serializable;
import java.sql.SQLException;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;
import javax.validation.constraints.Digits;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Pattern;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;

import org.hibernate.validator.constraints.Email;
import org.hibernate.validator.constraints.NotEmpty;

import com.vividsolutions.jts.geom.Geometry;
import com.vividsolutions.jts.geom.Point;
import com.vividsolutions.jts.io.ParseException;

import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.Type;
//import org.postgis.PGgeometry;
//import org.postgis.binary.BinaryParser;

import org.hibernate.spatial.GeometryType;

/*The Model uses JPA Entity as well as Hibernate Validators
 *
 */

@Entity
@XmlRootElement
@Table(name = "MemberHibernate4Demo", uniqueConstraints =
@UniqueConstraint(columnNames = "id"))
public class Member implements Serializable {
    /** Default value included to remove warning. Remove or modify at will. **/
    private static final long serialVersionUID = 1L;

    @Id
    private Long id;

    @NotNull
    @Size(min = 1, max = 25)
    @Pattern(regexp = "[A-Za-z ]*", message = "must contain only
letters and spaces")
    private String name;

    /** using hibernate4 validators **/
    @NotNull
    @NotEmpty
    @Email
    private String email;

    @NotNull
    @Size(min = 9, max = 12)
    @Digits(fraction = 0, integer = 12)
    @Column(name = "phone_number")
    private String phoneNumber;

    private String address;

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    private Geometry location;
    @Type(type="org.hibernate.spatial.GeometryType")
    @Column(name="location", columnDefinition="Geometry")
    public  Geometry getLocation() {
        return location;
    }

    public void setLocation(Geometry geom) {
        this.location = geom;
    }

    }

 }

I will appreciate if you show my wrong

kind regards

On Mon, Nov 19, 2012 at 2:07 PM, Jan Boonen <[hidden email]> wrote:

> Hi Ahmet,
>
> Could please post your entity mapping (either annotations of xml file) to
> the list. I think that there may be an error in your mapping.
>
> Cheers,
>
> Jan
>
>
> On 16-11-2012 20:20, Ahmet Temiz wrote:
>>
>> Hello
>>
>>
>> I want to store a POINT in postgis db
>> I am never able to solve this problem.
>>
>>
>>    String wktPoint="POINT(10 5)";
>>          Geometry geom = wktToGeometry(wktPoint);
>>
>>          String INSERT_SQL="INSERT INTO memberhibernate4demo
>> (id,location) values (2,?)";
>>
>> em.createNativeQuery(INSERT_SQL).setParameter(1,geom).executeUpdate();
>>
>>
>> 21:13:42,621 INFO  [stdout] (http--127.0.0.1-8080-1) Hibernate:
>> 21:13:42,621 INFO  [stdout] (http--127.0.0.1-8080-1)     INSERT
>> 21:13:42,622 INFO  [stdout] (http--127.0.0.1-8080-1)     INTO
>> 21:13:42,622 INFO  [stdout] (http--127.0.0.1-8080-1)
>> memberhibernate4demo
>> 21:13:42,622 INFO  [stdout] (http--127.0.0.1-8080-1)         (id,location)
>> 21:13:42,622 INFO  [stdout] (http--127.0.0.1-8080-1)     values
>> 21:13:42,622 INFO  [stdout] (http--127.0.0.1-8080-1)         (2,?)
>> 21:13:42,630 WARN  [org.hibernate.engine.jdbc.spi.SqlExceptionHelper]
>> (http--127.0.0.1-8080-1) SQL Error: 0, SQLState: 07006
>> 21:13:42,630 ERROR [org.hibernate.engine.jdbc.spi.SqlExceptionHelper]
>> (http--127.0.0.1-8080-1) Can't infer the SQL type to use for an
>> instance of org.postgis.PGgeometry. Use setObject() with an explicit
>> Types value to specify the type to use.
>>
>> ---
>>
>> what am I doing wrong ?
>>
>> regards
>>
>>
>>
>> --
>> Ahmet Temiz
>> Jeoloji Müh.
>> Afet ve Acil Durum Yönetimi Başkanlığı
>> Planlama ve Zarar Azaltma Dairesi Başkanlığı
>>
>> Eskişehir Yolu 10. km.
>> Lodumlu / Ankara
>> Tel : 0 312 2872680 / 1535
>> ________________________
>>
>> Ahmet Temiz
>> Geological Eng.
>> Information Systems - GIS Group
>> Disaster and Emergency Management
>> of Presidency
>> _______________________________________________
>> hibernatespatial-users mailing list
>> [hidden email]
>>
>> http://www.hibernatespatial.org/cgi-bin/mailman/listinfo/hibernatespatial-users
>
>
>
> _______________________________________________
> hibernatespatial-users mailing list
> [hidden email]
> http://www.hibernatespatial.org/cgi-bin/mailman/listinfo/hibernatespatial-users



--
Ahmet Temiz
Jeoloji Müh.
Afet ve Acil Durum Yönetimi Başkanlığı
Planlama ve Zarar Azaltma Dairesi Başkanlığı

Eskişehir Yolu 10. km.
Lodumlu / Ankara
Tel : 0 312 2872680 / 1535
________________________

Ahmet Temiz
Geological Eng.
Information Systems - GIS Group
Disaster and Emergency Management
of Presidency
_______________________________________________
hibernatespatial-users mailing list
[hidden email]
http://www.hibernatespatial.org/cgi-bin/mailman/listinfo/hibernatespatial-users
Reply | Threaded
Open this post in threaded view
|

Re: exception: "Can't infer the SQL type "

Jan Boonen
Hi Ahmet,

Thanks for posting this piece of code. Based on it, I think the problem
is that you are mixing annotations on fields with annotations on methods
(getter). If Hibernate encouters an annotation on a field it will ignore
properties on methods. Therefore it doesn't see your @Type annotation
for the Geometry column.

Also see the warning in the Hibernate Annotations documentation
(http://docs.jboss.org/hibernate/annotations/3.5/reference/en/html_single/#entity-mapping-entity).

Cheers,

Jan

On 19-11-2012 19:50, Ahmet Temiz wrote:

> here is the my entity class
>
>
> import java.io.Serializable;
> import java.sql.SQLException;
>
> import javax.persistence.Column;
> import javax.persistence.Entity;
> import javax.persistence.Id;
> import javax.persistence.Table;
> import javax.persistence.UniqueConstraint;
> import javax.validation.constraints.Digits;
> import javax.validation.constraints.NotNull;
> import javax.validation.constraints.Pattern;
> import javax.validation.constraints.Size;
> import javax.xml.bind.annotation.XmlRootElement;
>
> import org.hibernate.validator.constraints.Email;
> import org.hibernate.validator.constraints.NotEmpty;
>
> import com.vividsolutions.jts.geom.Geometry;
> import com.vividsolutions.jts.geom.Point;
> import com.vividsolutions.jts.io.ParseException;
>
> import org.hibernate.annotations.GenericGenerator;
> import org.hibernate.annotations.Type;
> //import org.postgis.PGgeometry;
> //import org.postgis.binary.BinaryParser;
>
> import org.hibernate.spatial.GeometryType;
>
> /*The Model uses JPA Entity as well as Hibernate Validators
>   *
>   */
>
> @Entity
> @XmlRootElement
> @Table(name = "MemberHibernate4Demo", uniqueConstraints =
> @UniqueConstraint(columnNames = "id"))
> public class Member implements Serializable {
>      /** Default value included to remove warning. Remove or modify at will. **/
>      private static final long serialVersionUID = 1L;
>
>      @Id
>      private Long id;
>
>      @NotNull
>      @Size(min = 1, max = 25)
>      @Pattern(regexp = "[A-Za-z ]*", message = "must contain only
> letters and spaces")
>      private String name;
>
>      /** using hibernate4 validators **/
>      @NotNull
>      @NotEmpty
>      @Email
>      private String email;
>
>      @NotNull
>      @Size(min = 9, max = 12)
>      @Digits(fraction = 0, integer = 12)
>      @Column(name = "phone_number")
>      private String phoneNumber;
>
>      private String address;
>
>      public Long getId() {
>          return id;
>      }
>
>      public void setId(Long id) {
>          this.id = id;
>      }
>
>      private Geometry location;
>      @Type(type="org.hibernate.spatial.GeometryType")
>      @Column(name="location", columnDefinition="Geometry")
>      public  Geometry getLocation() {
>          return location;
>      }
>
>      public void setLocation(Geometry geom) {
>          this.location = geom;
>      }
>
>      }
>
>   }
>
> I will appreciate if you show my wrong
>
> kind regards
>
> On Mon, Nov 19, 2012 at 2:07 PM, Jan Boonen <[hidden email]> wrote:
>> Hi Ahmet,
>>
>> Could please post your entity mapping (either annotations of xml file) to
>> the list. I think that there may be an error in your mapping.
>>
>> Cheers,
>>
>> Jan
>>
>>
>> On 16-11-2012 20:20, Ahmet Temiz wrote:
>>> Hello
>>>
>>>
>>> I want to store a POINT in postgis db
>>> I am never able to solve this problem.
>>>
>>>
>>>     String wktPoint="POINT(10 5)";
>>>           Geometry geom = wktToGeometry(wktPoint);
>>>
>>>           String INSERT_SQL="INSERT INTO memberhibernate4demo
>>> (id,location) values (2,?)";
>>>
>>> em.createNativeQuery(INSERT_SQL).setParameter(1,geom).executeUpdate();
>>>
>>>
>>> 21:13:42,621 INFO  [stdout] (http--127.0.0.1-8080-1) Hibernate:
>>> 21:13:42,621 INFO  [stdout] (http--127.0.0.1-8080-1)     INSERT
>>> 21:13:42,622 INFO  [stdout] (http--127.0.0.1-8080-1)     INTO
>>> 21:13:42,622 INFO  [stdout] (http--127.0.0.1-8080-1)
>>> memberhibernate4demo
>>> 21:13:42,622 INFO  [stdout] (http--127.0.0.1-8080-1)         (id,location)
>>> 21:13:42,622 INFO  [stdout] (http--127.0.0.1-8080-1)     values
>>> 21:13:42,622 INFO  [stdout] (http--127.0.0.1-8080-1)         (2,?)
>>> 21:13:42,630 WARN  [org.hibernate.engine.jdbc.spi.SqlExceptionHelper]
>>> (http--127.0.0.1-8080-1) SQL Error: 0, SQLState: 07006
>>> 21:13:42,630 ERROR [org.hibernate.engine.jdbc.spi.SqlExceptionHelper]
>>> (http--127.0.0.1-8080-1) Can't infer the SQL type to use for an
>>> instance of org.postgis.PGgeometry. Use setObject() with an explicit
>>> Types value to specify the type to use.
>>>
>>> ---
>>>
>>> what am I doing wrong ?
>>>
>>> regards
>>>
>>>
>>>
>>> --
>>> Ahmet Temiz
>>> Jeoloji Müh.
>>> Afet ve Acil Durum Yönetimi Başkanlığı
>>> Planlama ve Zarar Azaltma Dairesi Başkanlığı
>>>
>>> Eskişehir Yolu 10. km.
>>> Lodumlu / Ankara
>>> Tel : 0 312 2872680 / 1535
>>> ________________________
>>>
>>> Ahmet Temiz
>>> Geological Eng.
>>> Information Systems - GIS Group
>>> Disaster and Emergency Management
>>> of Presidency
>>> _______________________________________________
>>> hibernatespatial-users mailing list
>>> [hidden email]
>>>
>>> http://www.hibernatespatial.org/cgi-bin/mailman/listinfo/hibernatespatial-users
>>
>>
>> _______________________________________________
>> hibernatespatial-users mailing list
>> [hidden email]
>> http://www.hibernatespatial.org/cgi-bin/mailman/listinfo/hibernatespatial-users
>
>


_______________________________________________
hibernatespatial-users mailing list
[hidden email]
http://www.hibernatespatial.org/cgi-bin/mailman/listinfo/hibernatespatial-users