gpt4 book ai didi

mysql - org.hibernate.MappingException :Could not determine type for

转载 作者:行者123 更新时间:2023-11-29 07:27:57 28 4
gpt4 key购买 nike

我有典型的应用程序。 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

最佳答案

使用@Entity注释您的类意味着该类上的每个属性都必须在数据库上有其映射,除非它使用@Transient注释。

没有坐标列,这就是您收到异常的原因,解决方案是

@Transient
private Coordinates coordinates;

关于mysql - org.hibernate.MappingException :Could not determine type for,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33860704/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com