Hi,
I have a problem with a @onetoone annotation, that I've been unable to solve these last couple of days, despite reading almost every post on the subject.
Have a class called Vehicle that is link to a table called request, database model would look something like:
Vehicle
req_no(Primary key for this table, foreign key to request)
other suff
Request
req_no (Primary key, oracle seq generated)
other suff
The class Model at the moment looks something like this:
Code:
@Entity
@Table(name = "REQUEST")
public class Request implements Serializable
{
protected int id;
protected Vehicle vehicle;
@Id
@GeneratedValue(generator = "onlineReqSeq")
@Column(name = "REQ_NO", unique = true, nullable = false, precision = 9, scale = 0)
@SequenceGenerator(
name = "onlineReqSeq",
sequenceName = "SEQ_REQUEST_ID")
public int getId()
{
return id;
}
public void setId(int id
{
this.id= id
}
@OneToOne (mappedBy = "request")
public Vehicle getVehicle()
{
return vehicle
}
public void setVehicle(Vehicle vehicle)
{
this.vehicle) = vehicle;
}
}
Code:
@Entity
@Table(name = "VEHICLE")
public class Vehicle implements Serializable
{
/**
* Hibernate property facilitator
*/
private int vehicleID;
private Request request;
@Id
@GeneratedValue (generator = "foreign-gen")
@GenericGenerator(name = "foreign-gen", strategy = "foreign", parameters = {@Parameter(name =
"property", value = "request")})
@Column(name = "REQ_NO")
private int getVehicleID()
{
return vehicleID;// not used
}
private void setVehicleID(int vehicleID;
{
this.vehicleID;= vehicleID;
}
@OneToOne(optional = false)
@JoinColumn(name = "REQ_NO")
public Request getRequest()
{
return request;
}
public void setRequest(Request request)
{
this.request = request;
}
}
The problem is that the Request class can't find the request property of the vehicle. I've added in other 1-2-1s on the vehicle class and all is fine except when the vehicle has two references to the REQ_NO. I've hacked the hibernate source code a bit, and found out that when there are two REQ_NO, both properties are missing from the PersistentClass.getProperties method, they simply don't show up. I've tried all combinations of PrimaryKeyJoinColumn and insertable etc., but not having any luck. I suspect the problem is that the reference is essentially backward, i.e. the request should really have a link to the vehicle, but that's the data model we're stuck with and think hibernate should be able to handle it. I noticed that some issues similar to this might be fixed in 3.2.2 any date for that yet?
Any help fixing this will be appreciated. and points will be awarded.
Many thanks,
Chris.