2015-11-22 121 views
0

我有典型的應用程序。春季4 MVC + Hibernate的4 + MYSQL + Maven的整合使用註釋,使用基於註解的配置與Hibernate集成Springorg.hibernate.MappingException:無法確定類型

我有這樣的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 

回答

2

Annotatin g @Entity表示該類的每個屬性都必須在分貝上有其映射,除非其註釋爲@Transient

沒有爲coordinates這就是爲什麼你所得到的異常沒有列,一個解決辦法是

@Transient 
private Coordinates coordinates; 
相關問題