-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: Primary/Foreign Key @onetoone
PostPosted: Tue Feb 20, 2007 2:17 pm 
Newbie

Joined: Fri Jan 26, 2007 9:58 am
Posts: 18
Location: Dublin
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.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 20, 2007 4:32 pm 
Regular
Regular

Joined: Mon May 22, 2006 2:30 pm
Posts: 74
FYI, Hibernate 3.2.2 GA is already available.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 21, 2007 6:38 am 
Newbie

Joined: Fri Jan 26, 2007 9:58 am
Posts: 18
Location: Dublin
Thanks for the reply but it's annotations 3.2.2 that I think we need, which still has four errors due to be fixed before release. Should have been more clear.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.