Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/397.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何使用hbm.xml文件从sql获取计算字段到hibernate_Java_Hibernate - Fatal编程技术网

Java 如何使用hbm.xml文件从sql获取计算字段到hibernate

Java 如何使用hbm.xml文件从sql获取计算字段到hibernate,java,hibernate,Java,Hibernate,下面给出了类、Hbm和DAO Impl文件。 调用address.getDistance()方法时,我得到的是空值 如何获得从sql到hibernate类的计算距离 Address.hbm.xml AddressDAOIMpl方法来计算距离 @SuppressWarnings(“未选中”) 公共列表ListAddressBytitudeAndLongitate(双纬度、双经度){ Query Query=getSession().createSQLQuery(“选择*,((ACOS(SIN:la

下面给出了类、Hbm和DAO Impl文件。 调用address.getDistance()方法时,我得到的是空值

如何获得从sql到hibernate类的计算距离

Address.hbm.xml AddressDAOIMpl方法来计算距离
@SuppressWarnings(“未选中”)
公共列表ListAddressBytitudeAndLongitate(双纬度、双经度){
Query Query=getSession().createSQLQuery(“选择*,((ACOS(SIN:latitude*PI()/180)*SIN(latitude*PI()/180)+COS(:latitude*PI()/180)”+
“*COS(纬度*PI()/180)*COS(:经度*PI()/180))*180/PI())*60*1.1515)作为与地址a的距离”+

“有距离我不太明白这个问题。POJO的
distance
字段没有以任何方式映射到Hibernate(既不是作为字段也不是作为。你想做什么?
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
    <class name="com.lb.bb.model.Address" table="address" catalog="bb">
        <id name="addressId" type="java.lang.Integer">
            <column name="address_id" />
            <generator class="identity" />
        </id>
        <property name="addressLine" type="string" column="address_line" length="200" not-null="true"/>
        <property name="city" type="string" column="city" length="200" not-null="true"/>
        <property name="cityUrl" type="string" column="city_url" length="200" not-null="true"/>
        <property name="state" type="string" column="state" length="200" not-null="true"/>
        <property name="country" type="string" column="country" length="200" not-null="true"/>
        <property name="zipcode" type="string" column="zipcode" length="100" not-null="true"/>
        <property name="phoneno" type="string" column="phoneno" length="100" not-null="true"/>
        <property name="latitude" type="double" column="latitude" not-null="true"/>
        <property name="longitude" type="double" column="longitude" not-null="true" />
    </class>
</hibernate-mapping>
public class Address implements java.io.Serializable{

private static final long serialVersionUID = -2587677535225820165L;

    private Integer addressId;
    private String addressLine;
    private String city;
    private String cityUrl;
    private String state;
    private String country;
    private String zipcode;
    private String phoneno;
    private Double latitude;
    private Double longitude;
    private Double distance;

    public Address(){

    }
}
@SuppressWarnings("unchecked")
public List<Address> listAddressByLatitudeAndLongitude(Double latitude, Double longitude) {

    Query query = getSession().createSQLQuery("SELECT *, ((ACOS(SIN(:latitude * PI() / 180) * SIN(latitude * PI() / 180) + COS(:latitude * PI() / 180)" +
            " * COS(latitude * PI() / 180) * COS((:longitude - longitude) * PI() / 180)) * 180 / PI()) * 60 * 1.1515) AS distance FROM address a " +
            "HAVING distance<=1000 ORDER BY distance ASC").addEntity(Address.class)
            .setParameter("latitude", latitude).setParameter("longitude", longitude);
    return (List<Address>) query.list();
}