Hi
I am very new to EJB3.0. I have some doubt on the following one to one uni-directional
realtionship.
@Entity (name = "Orders2")
@Table(name = "Orders2")
public class Orders implements Serializable {
@Id
@Basic(optional = false)
@Column(name = "OrderId")
private
String orderId;
@Column(name = "OrderName")
private String orderName;
@OneToOne(cascade={CascadeType.PERSIST})
private Shipments objShipment;
}
@Entity(name = "Shipments2")
@Table(name = "Shipments2")
public class Shipments implements Serializable {
@Id
@Basic(optional = false)
@Column(name = "ShpmentId")
private String shpmentId;
@Column(name = "City")
private String city;
}
Based on the above relationship, I have some queries
A) the underlying table have following columns
Orders2 -table
OrderId , OrderName ,OBJSHIPMENT_SHPMENTID
Shipments2 -table
ShpmentId, City
Am I right sir?
B) If I write @PrimaryKeyJoinColumn (name="OrderId",referencedColumnName="ShpmentId") just above
private Shipments objShipment in the Orders class, then changed fields are
Orders2 -table
OrderId , OrderName
Shipments2 -table
ShpmentId, City
we can dropped OBJSHIPMENT_SHPMENTID field in the Orders2 table.
Please, rectify me If I am mistaken.
C) If I write
@JoinColumn(name="Relationship",referencedColumnName="ShpmentId")
just above private Shipments objShipment in the Orders class then changed tables are as
follows:
Orders2 -table
OrderId , OrderName, Relationship
Shipments2 -table
ShpmentId, City
Relationship acts as Foreign key to ShipmentId Primary Key
Is it so?
D) what 's the significance of name attribute of the adjacent annotation @Entity (name = "Orders2"). If i simply write @Entity for both of the classes, Persistenec is not happening
at all.