mercredi 5 août 2015

Hibernate entity virtual column error?


I have defined a virtual column distanceInKm in my Entity for some distance calculation and giving response to the user along with distanceInKm which is a virtual column not a column in my table,and it's working well (case 1).

now am using the same entity for fetching all the values from the table but am getting com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown column 'restaurant0_.distanceInKm' in 'field list'.(case 2)

I came to know the usage of @Transiant annotation for virtual columns which is used for calculation.but if am using that the virtual column will not be serialized/added to user response in (case 1).i need to implement both the API ie , Case 1 & Case 2 by using one entity

 @Entity
    @Table(name = "restaurants")
    public class Restaurants implements Serializable {

        private static final long serialVersionUID = 1L;

        @Id
        @GeneratedValue(strategy = GenerationType.IDENTITY)
        @Column(name = "restaurant_id")
        private int restaurantId;

        @Column(name = "restaurant_name")
        private String restaurantName;

        @Column(name = "category_id")
        private Integer categoryId;

        @Column(name = "image_url")
        private String imageUrl;

        private Float longitude;

        private Float latitude;

        @Column(name = "contact_name")
        private String contactName;

        @Column(name = "primary_phone")
        private String primaryPhone;

        @Column(name = "secondary_phone")
        private String secondaryPhone;

        private String fax;

        private String address1;

        private String address2;

        @Column(insertable = false, updatable = false)
        private String distanceInKm;/*Virtual column*/

}

Help is appreciated.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire