类表配置休眠

时间:2013-07-04 17:18:22

标签: spring hibernate orm spring-jdbc

我是hibernate的新手并尝试运行应用程序,但我在运行应用程序时遇到问题。 我得到以下错误,

org.hibernate.MappingException: Unknown entity: DELETE com.on.transport.dto.updated.RoutePlaceMappingUpdated rpmu where rpmu.route.routeId=?


@Entity
@Table(name = "route_place_mapping")
public class RoutePlaceMappingUpdated {

@Id @GeneratedValue
@Column(name = "route_place_mapping_id")
private Long routePlaceMappingId;

@OneToOne(targetEntity=RouteUpdated.class)
@JoinColumn(name="route_id")
private RouteUpdated route;

@OneToOne(targetEntity=PlaceUpdated.class)
@JoinColumn(name="place_id")
private PlaceUpdated place;


@Temporal(TemporalType.TIMESTAMP)
@Column(name = "arrival_time", nullable=false, length=19)
private Date arrivalTime;

@Column(name = "sequence_of_arrival")
private String sequenceArrivalAtPlace;

//getter - setter
}


@Entity
@Table(name = "route")
public class RouteUpdated {

    @Id @GeneratedValue
    @Column(name = "route_id")
    private Long routeId;

    @Column(name = "route_name")
    private String routeName;

//getter-setter
}


@Entity
@Table(name = "place")
public class PlaceUpdated {


    @Id @GeneratedValue
    @Column(name = "place_id")
    private Long placeId;

    @Column(name = "place_name")
    private String placeName;   

//getter-setter
}

我正在调用以下函数,我收到错误。

@Override
public boolean deleteAllInBetweenPlaceOfRouteByRouteId(Long routeId){
    String hql1 = "DELETE com.on.transport.dto.updated.RoutePlaceMappingUpdated rpmu where rpmu.route.routeId=?";
    Object[] queryParam = {routeId};
    getHibernateTemplate().delete(hql1, queryParam);
    return true;
}

TABLE-STRUCTURE

route
---------------
route_id int
route_name varchar


place
---------------
place_id int
place_name varchar


route_place_mapping
----------------------
route_place_mapping_id   int
route_id int
place_id int

我在路由和地方属性的RoutePlaceMappingUpdated类中遗漏了一些东西,但我无法理解。

1 个答案:

答案 0 :(得分:0)

你正在超越异常,因为hibernate将DELETE视为一个实体并试图找到它,但显然无法找到它。