• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Rob Spoor
  • Bear Bibeault
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:
  • Frits Walraven
  • Himai Minh

Please explain this @OneToOne

 
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.






 
author
Posts: 580
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 580
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic