UnsupportedOperationException in Hibernate Spatial 4.0.1

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

UnsupportedOperationException in Hibernate Spatial 4.0.1

dufeng

Hi,

 

When persistent polygon come up several exceptions.

I use Postgres 9.2 , Hibernate 4.0.1(JBoss as 7 default implementation), Hibernate spatial 4.0 and Postgis 2.0.1 to persistent the geometry data.

 

1.The following is entity design code. I delare a attribute polygonAOI (com.vividsolutions.jts.geom.Polygon).

///////////////////////////////////////////////////////Entity POJO Definition//////////////////////////

 

import org.hibernate.annotations.Type;

import com.vividsolutions.jts.geom.Polygon;

 

@Entity

@Table(name="areaofinterest",uniqueConstraints=@UniqueConstraint(columnNames={"areaofinterestid"}))

public class AreaOfInterest {

       /**

       * areaofInterestId the primary key value.Automatically grows when insert new row.

       */

       @Id

       @GeneratedValue(strategy=GenerationType.IDENTITY)

       @Column(name="areaofinterestid")

       private Integer areaofInterestId;

      

       /**

       * One project only has one area of interest.Define the related project information.

       * OneToOne(fetch=FetchType.EAGER,mappedBy="AOI",targetEntity=Project.class,cascade=CascadeType.REFRESH)

       */

       @OneToOne(fetch=FetchType.EAGER,targetEntity=Project.class,cascade=CascadeType.PERSIST)

       @JoinColumn(name="projectID",nullable=true)

       private Project project;

      

       /**

       * The name of the area of interest.

       */

       @Column(name="aoiname",nullable=true)

       private String aoiName;

      

       /**

       * The type of the area of interest with the AOIType enumeration.

       */

       @Column(name="aoitype",nullable=true)

       @Enumerated(EnumType.STRING)

       private AOIType aoiType;

      

       /**

       * The AOI specific information using polygon type.

        */

       @Column(name="polygonaoi",columnDefinition="Geometry")          

       @Type(type="org.hibernate.spatial.GeometryType")

       private Polygon polygonAOI;

....

///////////////////////////////////////////////////////////////////////////////////////////////////////

2. This code invoked by client to save the polygon from the map view.

All following geometry object uses the com.vividsolutions.jts.geom.* from jts-1.12.jar.

 

   @PersistenceContext(unitName="meta_data")

       private EntityManager em;

 

   Coordinate[] xy = new Coordinate[5];

       xy[0] = new Coordinate(0,0);

       xy[2] = new Coordinate(1000,1000);

       xy[3] = new Coordinate(1000,0);

       xy[1] = new Coordinate(0,1000);

       xy[4] = new Coordinate(0,0);         

                                  

       GeometryFactory geometryFactory = new GeometryFactory(new PrecisionModel(),4326);

       LinearRing ring = geometryFactory.createLinearRing(xy);

       LinearRing holes[] = null;

       Polygon polygon = geometryFactory.createPolygon(ring, holes );

             

AreaOfInterest aoi = new AOIInfo();

aoi.aoiName = "ploygon1";

   aoi.aoiType = AOIType.Perferred_Zones;

   aoi.polygonAOI = polygon;

   em.persistent(aoi);

       

3.Come up following exceptions.All this utilize the JPA 2.0 to implement the data persistent and act as a local session bean depployed in the JBoss as 7.1.1.

What is wrong with my code?Should I use directly the JTS object to save in the database?

Please give some guidance .Thanks a lot.

 

Caused by: java.lang.UnsupportedOperationException

       at org.hibernate.spatial.GeometrySqlTypeDescriptor.getBinder(GeometrySqlTypeDescriptor.java:52) [hibernate-spatial-4.0-M1.jar:4.0.0.Final]

       at org.hibernate.type.AbstractStandardBasicType.nullSafeSet(AbstractStandardBasicType.java:305) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]

       at org.hibernate.type.AbstractStandardBasicType.nullSafeSet(AbstractStandardBasicType.java:300) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]

       at org.hibernate.type.AbstractSingleColumnStandardBasicType.nullSafeSet(AbstractSingleColumnStandardBasicType.java:57) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]

       at org.hibernate.persister.entity.AbstractEntityPersister.dehydrate(AbstractEntityPersister.java:2593) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]

       at org.hibernate.persister.entity.AbstractEntityPersister.dehydrate(AbstractEntityPersister.java:2570) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]

       at org.hibernate.persister.entity.AbstractEntityPersister$4.bindValues(AbstractEntityPersister.java:2751) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]

       at org.hibernate.id.insert.AbstractReturningDelegate.performInsert(AbstractReturningDelegate.java:54) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]

       at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2757) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]

       at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:3268) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]

       at org.hibernate.action.internal.EntityIdentityInsertAction.execute(EntityIdentityInsertAction.java:78) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]

       at org.hibernate.engine.spi.ActionQueue.execute(ActionQueue.java:272) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]

       at org.hibernate.event.internal.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:304) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]

       at org.hibernate.event.internal.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:195) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]

       at org.hibernate.event.internal.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:128) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]

       at org.hibernate.ejb.event.EJB3PersistEventListener.saveWithGeneratedId(EJB3PersistEventListener.java:78) [hibernate-entitymanager-4.0.1.Final.jar:4.0.1.Final]

       at org.hibernate.event.internal.DefaultPersistEventListener.entityIsTransient(DefaultPersistEventListener.java:208) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]

       at org.hibernate.event.internal.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:151) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]

       at org.hibernate.event.internal.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:78) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]

       at org.hibernate.internal.SessionImpl.firePersist(SessionImpl.java:725) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]

       at org.hibernate.internal.SessionImpl.persist(SessionImpl.java:701) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]

       at org.hibernate.internal.SessionImpl.persist(SessionImpl.java:705) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]

       at org.hibernate.ejb.AbstractEntityManagerImpl.persist(AbstractEntityManagerImpl.java:853) [hibernate-entitymanager-4.0.1.Final.jar:4.0.1.Final]

       at org.jboss.as.jpa.container.AbstractEntityManager.persist(AbstractEntityManager.java:563) [jboss-as-jpa-7.1.1.Final.jar:7.1.1.Final]

       at com.astrium.geo.sf.workflow.eao.impl.CommonEaoImpl.save(CommonEaoImpl.java:64) [SFService.jar:]

       at com.astrium.geo.sf.workflow.eao.impl.AOIEaoImpl.newProjectAOI(AOIEaoImpl.java:63) [SFService.jar:]

       at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [rt.jar:1.6.0_35]

       at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) [rt.jar:1.6.0_35]

       at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) [rt.jar:1.6.0_35]

       at java.lang.reflect.Method.invoke(Method.java:597) [rt.jar:1.6.0_35]

       at org.jboss.as.ee.component.ManagedReferenceMethodInterceptorFactory$ManagedReferenceMethodInterceptor.processInvocation(ManagedReferenceMethodInterceptorFactory.java:72) [jboss-as-ee-7.1.1.Final.jar:7.1.1.Final]

       at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]

       at org.jboss.invocation.WeavedInterceptor.processInvocation(WeavedInterceptor.java:53) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]

       at org.jboss.as.ee.component.interceptors.UserInterceptorFactory$1.processInvocation(UserInterceptorFactory.java:36) [jboss-as-ee-7.1.1.Final.jar:7.1.1.Final]

       at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]

       at org.jboss.as.jpa.interceptor.SBInvocationInterceptor.processInvocation(SBInvocationInterceptor.java:47) [jboss-as-jpa-7.1.1.Final.jar:7.1.1.Final]

       at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]

       at org.jboss.invocation.InitialInterceptor.processInvocation(InitialInterceptor.java:21) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]

       at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]

       at org.jboss.invocation.ChainedInterceptor.processInvocation(ChainedInterceptor.java:61) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]

       at org.jboss.as.ee.component.interceptors.ComponentDispatcherInterceptor.processInvocation(ComponentDispatcherInterceptor.java:53) [jboss-as-ee-7.1.1.Final.jar:7.1.1.Final]

       at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]

       at org.jboss.as.ejb3.component.pool.PooledInstanceInterceptor.processInvocation(PooledInstanceInterceptor.java:51) [jboss-as-ejb3-7.1.1.Final.jar:7.1.1.Final]

       at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]

       at org.jboss.as.ejb3.tx.CMTTxInterceptor.invokeInCallerTx(CMTTxInterceptor.java:202) [jboss-as-ejb3-7.1.1.Final.jar:7.1.1.Final]

       ... 67 more

 

Thanks and Regards,
Feng

 


_______________________________________________
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: UnsupportedOperationException in Hibernate Spatial 4.0.1

Karel Maesen
Administrator
Hello Du Feng,

Your code looks correct. The most likely cause of this error is that the SpatialDialect for Postgis is not configured. During application start-up make sure that you see a log message that PostgisDialect is used.

Sometimes it happens with Spring that the framework decides on the PostgreSQL Dialect based on your JDBC driver. So you must ensure that the correct dialect is explicitly configured.

Regards,

Karel

On 26 Nov 2012, at 14:11, Du Feng wrote:

> Hi,
>  
> When persistent polygon come up several exceptions.
> I use Postgres 9.2 , Hibernate 4.0.1(JBoss as 7 default implementation), Hibernate spatial 4.0 and Postgis 2.0.1 to persistent the geometry data.
>  
> 1.The following is entity design code. I delare a attribute polygonAOI (com.vividsolutions.jts.geom.Polygon).
> ///////////////////////////////////////////////////////Entity POJO Definition//////////////////////////
>  
> import org.hibernate.annotations.Type;
> import com.vividsolutions.jts.geom.Polygon;
>  
> @Entity
> @Table(name="areaofinterest",uniqueConstraints=@UniqueConstraint(columnNames={"areaofinterestid"}))
> public class AreaOfInterest {
>        /**
>        * areaofInterestId the primary key value.Automatically grows when insert new row.
>        */
>        @Id
>        @GeneratedValue(strategy=GenerationType.IDENTITY)
>        @Column(name="areaofinterestid")
>        private Integer areaofInterestId;
>      
>        /**
>        * One project only has one area of interest.Define the related project information.
>        * OneToOne(fetch=FetchType.EAGER,mappedBy="AOI",targetEntity=Project.class,cascade=CascadeType.REFRESH)
>        */
>        @OneToOne(fetch=FetchType.EAGER,targetEntity=Project.class,cascade=CascadeType.PERSIST)
>        @JoinColumn(name="projectID",nullable=true)
>        private Project project;
>      
>        /**
>        * The name of the area of interest.
>        */
>        @Column(name="aoiname",nullable=true)
>        private String aoiName;
>      
>        /**
>        * The type of the area of interest with the AOIType enumeration.
>        */
>        @Column(name="aoitype",nullable=true)
>        @Enumerated(EnumType.STRING)
>        private AOIType aoiType;
>      
>        /**
>        * The AOI specific information using polygon type.
>         */
>        @Column(name="polygonaoi",columnDefinition="Geometry")          
>        @Type(type="org.hibernate.spatial.GeometryType")
>        private Polygon polygonAOI;
> ....
> ///////////////////////////////////////////////////////////////////////////////////////////////////////
> 2. This code invoked by client to save the polygon from the map view.
> All following geometry object uses the com.vividsolutions.jts.geom.* from jts-1.12.jar.
>  
>    @PersistenceContext(unitName="meta_data")
>        private EntityManager em;
>  
>    Coordinate[] xy = new Coordinate[5];
>        xy[0] = new Coordinate(0,0);
>        xy[2] = new Coordinate(1000,1000);
>        xy[3] = new Coordinate(1000,0);
>        xy[1] = new Coordinate(0,1000);
>        xy[4] = new Coordinate(0,0);        
>                                  
>        GeometryFactory geometryFactory = new GeometryFactory(new PrecisionModel(),4326);
>        LinearRing ring = geometryFactory.createLinearRing(xy);
>        LinearRing holes[] = null;
>        Polygon polygon = geometryFactory.createPolygon(ring, holes );
>              
> AreaOfInterest aoi = new AOIInfo();
> aoi.aoiName = "ploygon1";
>    aoi.aoiType = AOIType.Perferred_Zones;
>    aoi.polygonAOI = polygon;
>    em.persistent(aoi);
>        
> 3.Come up following exceptions.All this utilize the JPA 2.0 to implement the data persistent and act as a local session bean depployed in the JBoss as 7.1.1.
> What is wrong with my code?Should I use directly the JTS object to save in the database?
> Please give some guidance .Thanks a lot.
>  
> Caused by: java.lang.UnsupportedOperationException
>        at org.hibernate.spatial.GeometrySqlTypeDescriptor.getBinder(GeometrySqlTypeDescriptor.java:52) [hibernate-spatial-4.0-M1.jar:4.0.0.Final]
>        at org.hibernate.type.AbstractStandardBasicType.nullSafeSet(AbstractStandardBasicType.java:305) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
>        at org.hibernate.type.AbstractStandardBasicType.nullSafeSet(AbstractStandardBasicType.java:300) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
>        at org.hibernate.type.AbstractSingleColumnStandardBasicType.nullSafeSet(AbstractSingleColumnStandardBasicType.java:57) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
>        at org.hibernate.persister.entity.AbstractEntityPersister.dehydrate(AbstractEntityPersister.java:2593) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
>        at org.hibernate.persister.entity.AbstractEntityPersister.dehydrate(AbstractEntityPersister.java:2570) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
>        at org.hibernate.persister.entity.AbstractEntityPersister$4.bindValues(AbstractEntityPersister.java:2751) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
>        at org.hibernate.id.insert.AbstractReturningDelegate.performInsert(AbstractReturningDelegate.java:54) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
>        at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2757) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
>        at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:3268) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
>        at org.hibernate.action.internal.EntityIdentityInsertAction.execute(EntityIdentityInsertAction.java:78) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
>        at org.hibernate.engine.spi.ActionQueue.execute(ActionQueue.java:272) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
>        at org.hibernate.event.internal.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:304) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
>        at org.hibernate.event.internal.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:195) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
>        at org.hibernate.event.internal.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:128) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
>        at org.hibernate.ejb.event.EJB3PersistEventListener.saveWithGeneratedId(EJB3PersistEventListener.java:78) [hibernate-entitymanager-4.0.1.Final.jar:4.0.1.Final]
>        at org.hibernate.event.internal.DefaultPersistEventListener.entityIsTransient(DefaultPersistEventListener.java:208) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
>        at org.hibernate.event.internal.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:151) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
>        at org.hibernate.event.internal.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:78) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
>        at org.hibernate.internal.SessionImpl.firePersist(SessionImpl.java:725) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
>        at org.hibernate.internal.SessionImpl.persist(SessionImpl.java:701) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
>        at org.hibernate.internal.SessionImpl.persist(SessionImpl.java:705) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
>        at org.hibernate.ejb.AbstractEntityManagerImpl.persist(AbstractEntityManagerImpl.java:853) [hibernate-entitymanager-4.0.1.Final.jar:4.0.1.Final]
>        at org.jboss.as.jpa.container.AbstractEntityManager.persist(AbstractEntityManager.java:563) [jboss-as-jpa-7.1.1.Final.jar:7.1.1.Final]
>        at com.astrium.geo.sf.workflow.eao.impl.CommonEaoImpl.save(CommonEaoImpl.java:64) [SFService.jar:]
>        at com.astrium.geo.sf.workflow.eao.impl.AOIEaoImpl.newProjectAOI(AOIEaoImpl.java:63) [SFService.jar:]
>        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [rt.jar:1.6.0_35]
>        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) [rt.jar:1.6.0_35]
>        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) [rt.jar:1.6.0_35]
>        at java.lang.reflect.Method.invoke(Method.java:597) [rt.jar:1.6.0_35]
>        at org.jboss.as.ee.component.ManagedReferenceMethodInterceptorFactory$ManagedReferenceMethodInterceptor.processInvocation(ManagedReferenceMethodInterceptorFactory.java:72) [jboss-as-ee-7.1.1.Final.jar:7.1.1.Final]
>        at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]
>        at org.jboss.invocation.WeavedInterceptor.processInvocation(WeavedInterceptor.java:53) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]
>        at org.jboss.as.ee.component.interceptors.UserInterceptorFactory$1.processInvocation(UserInterceptorFactory.java:36) [jboss-as-ee-7.1.1.Final.jar:7.1.1.Final]
>        at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]
>        at org.jboss.as.jpa.interceptor.SBInvocationInterceptor.processInvocation(SBInvocationInterceptor.java:47) [jboss-as-jpa-7.1.1.Final.jar:7.1.1.Final]
>        at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]
>        at org.jboss.invocation.InitialInterceptor.processInvocation(InitialInterceptor.java:21) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]
>        at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]
>        at org.jboss.invocation.ChainedInterceptor.processInvocation(ChainedInterceptor.java:61) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]
>        at org.jboss.as.ee.component.interceptors.ComponentDispatcherInterceptor.processInvocation(ComponentDispatcherInterceptor.java:53) [jboss-as-ee-7.1.1.Final.jar:7.1.1.Final]
>        at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]
>        at org.jboss.as.ejb3.component.pool.PooledInstanceInterceptor.processInvocation(PooledInstanceInterceptor.java:51) [jboss-as-ejb3-7.1.1.Final.jar:7.1.1.Final]
>        at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]
>        at org.jboss.as.ejb3.tx.CMTTxInterceptor.invokeInCallerTx(CMTTxInterceptor.java:202) [jboss-as-ejb3-7.1.1.Final.jar:7.1.1.Final]
>        ... 67 more
>  
> Thanks and Regards,
> Feng
>  
> _______________________________________________
> 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