Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Please explain this @OneToOne

 
Gautam Ry
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.






 
Reza Rahman
author
Ranch Hand
Posts: 580
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Gautam,

You are correct. I never use @Entity.name.

Hope it helps,
Reza
 
Gautam Ry
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Reza
thanks for your response. But I didn't get you.
Should I write @Entity (name = "Orders2") or not?
If I write so, then what will be the value of name?
Will it be the table name where the entity will
be persisted?
Please, look into my other questions.
I am stuck.

Gautam


 
Reza Rahman
author
Ranch Hand
Posts: 580
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Gautam,

The entity name is defaulted to the unqualified name of the class. It is only needed to resolve class duplication issues, which never happens in real life.

Hope it helps,
Reza
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic