0

我在 JBOSS 服务器上使用 Hibernate + HSQL,我需要 saveOrUpdate() 一个对象,它的 ID 由另一个类表示:

public class RideId implements java.io.Serializable {

    private int beginPop;
    private int endPop;
    private String requestUser;

public RideId() {
}

public RideId(int beginPop, int endPop, String requestUser) {
    this.beginPop = beginPop;
    this.endPop = endPop;
    this.requestUser = requestUser;
}
...

因此,“RideID”是实体“Ride”的 ID

public class Ride implements java.io.Serializable {

private RideId id;
private User userByRequestUser;
private User userByAcceptUser;
private Pop pop;
private Boolean rideStatus;

public Ride() {
}

public Ride(RideId id, User userByRequestUser, Pop pop) {
    this.id = id;
    this.userByRequestUser = userByRequestUser;
    this.pop = pop;
}

public Ride(RideId id, User userByRequestUser, User userByAcceptUser,
        Pop pop, Boolean rideStatus) {
    this.id = id;
    this.userByRequestUser = userByRequestUser;
    this.userByAcceptUser = userByAcceptUser;
    this.pop = pop;
    this.rideStatus = rideStatus;
}
...

我怎样才能 saveOrUpdate() 类型 Ride 的新对象?

谢谢大家,对不起我的英语!

4

1 回答 1

0

这很简单。您需要先创建一个 new RideId,将其分配给一个 newRidesaveOrUpdate使用Ride.

RideId id = new RideId(1, 2, "someuser");
Ride ride = new Ride(id, ...);
session.saveOrUpdate(ride);
于 2013-04-09T09:50:20.350 回答