org.hibernate.MappingException:无法确定

时间:2015-11-22 21:54:15

标签: mysql hibernate spring-mvc

我有一个典型的应用程序。 Spring 4使用注释进行MVC + Hibernate 4 + MySQL + Maven集成,使用基于注释的配置将Spring与Hibernate集成

我有这个MySQL表:

CREATE TABLE `t_device_event` (
  `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
  `device_event_lat` float(10,6) DEFAULT NULL,
  `device_event_lng` float(10,6) unsigned NOT NULL
) 

和这堂课:

@Entity
@Table(name="t_device_event")
public class DeviceEvent {

        public class Coordinates {

            @Column(name = "device_event_lat")
            private Float lat;

            @Column(name = "device_event_lng")
            private Float lng;

            public Float getLat() {
                return lat;
            }

            public void setLat(Float lat) {
                this.lat = lat;
            }

            public Float getLng() {
                return lng;
            }

            public void setLng(Float lng) {
                this.lng = lng;
            }

            public Coordinates(Float lat, Float lng) {
                super();
                this.lat = lat;
                this.lng = lng;
            }   
        }

        @Id
        @GeneratedValue(strategy = GenerationType.IDENTITY)
        private int id;

        private Coordinates coordinates;

        public Coordinates getCoordinates() {
            return coordinates;
        }



       public void setCoordinates(Coordinates coordinates) {
            this.coordinates = coordinates;
        }

        public int getId() {
            return id;
        }

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

但是在初始化应用程序时我遇到了这个错误:

Caused by: org.hibernate.MappingException: Could not determine type for: fr.telecom.model.DeviceEvent$Coordinates, at table: t_device_event, for columns: [org.hibernate.mapping.Column(coordinates)]
    at org.hibernate.mapping.SimpleValue.getType(SimpleValue.java:336)
    at org.hibernate.mapping.SimpleValue.isValid(SimpleValue.java:310)
    at org.hibernate.mapping.Property.isValid(Property.java:241)
    at org.hibernate.mapping.PersistentClass.validate(PersistentClass.java:496)
    at org.hibernate.mapping.RootClass.validate(RootClass.java:270)
    at org.hibernate.cfg.Configuration.validate(Configuration.java:1358)
    at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1849)
    at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1928)
    at org.springframework.orm.hibernate4.LocalSessionFactoryBuilder.buildSessionFactory(LocalSessionFactoryBuilder.java:343)
    at org.springframework.orm.hibernate4.LocalSessionFactoryBean.buildSessionFactory(LocalSessionFactoryBean.java:431)
    at org.springframework.orm.hibernate4.LocalSessionFactoryBean.afterPropertiesSet(LocalSessionFactoryBean.java:416)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1612)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1549)
    ... 70 more

1 个答案:

答案 0 :(得分:2)

使用reading = reading & (max_output-1)注释您的类意味着该类上的每个属性都必须在db上具有映射,除非使用@Entity进行注释。

@Transient没有列,这就是你获得异常的原因,解决方案就是

coordinates