Note that there are some explanatory texts on larger screens.

plurals
  1. POReturning spatial data with Hibernate
    primarykey
    data
    text
    <p>I am trying to return spatial data (ie Point) from database using Hibernate Spatial library (http://www.hibernatespatial.org/) using this WORKING approach...</p> <pre><code> ... Session session = sessionFactory.openSession(); Query query = session.createQuery("select location, distance(location, :requestPoint) from "+Event.class.getName()); query.setParameter("requestPoint", requestPoint); List&lt;?&gt; rows = query.list(); session.close(); List&lt;Event&gt; events = new ArrayList&lt;Event&gt;(); for (Iterator&lt;?&gt; it = rows.iterator(); it.hasNext(); ) { Object[] row = (Object[]) it.next(); Event event = new Event(); event.setLocation((Point) row[0]); event.setDistance((Double) row[1]); events.add(event); } return events; </code></pre> <p>but I would like to use something like this (use Event class constructor in select statment)...</p> <pre><code> Session session = sessionFactory.openSession(); Query query = session.createQuery("select new Event(location, distance(location, :requestPoint)) from "+Event.class.getName()); query.setParameter("requestPoint", requestPoint); List&lt;Event&gt; rows = query.list(); session.close(); return rows; </code></pre> <p>The problem is that the second approach gives me following exception...</p> <pre><code>org.hibernate.hql.internal.ast.QuerySyntaxException: Unable to locate appropriate constructor on class [com.jaygridley.aet.Event] [select new Event(location, distance(location, :requestPoint)) from com.jaygridley.aet.domain.Event] </code></pre> <p>but I cannot see why, because inside of my Event class I have a constructor...</p> <pre><code>public Event(Point location, Double distance) { this.location = location; this.distance = distance; } </code></pre> <p>for clarity Event class has following properties...</p> <pre><code>@Column(name="LOCATION", columnDefinition = "MDSYS.SDO_GEOMETRY", nullable = false) @Type(type = "org.hibernate.spatial.GeometryType") private Point location; private Double distance; </code></pre> <p>I have checked return class for each column that Hibernate returns and it matches Point and Double. Does anyone has any idea what I am doing wrong? Thanks you!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload