Link to home
Start Free TrialLog in
Avatar of gudii9
gudii9Flag for United States of America

asked on

hibernate one to one

Hi,

I was going through hibernate one-one example


http://www.mkyong.com/hibernate/hibernate-one-to-one-relationship-example-annotation/

In the main class why Stock is set to StockDetail object and also StockDetail set to Stock in both ways(is setting one way is not enough?)


stock.setStockDetail(stockDetail);
stockDetail.setStock(stock);

Please advice
ASKER CERTIFIED SOLUTION
Avatar of Sammy
Sammy
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of gudii9

ASKER

@Entity
@Table(name = "stock", catalog = "mkyongdb", uniqueConstraints = {
            @UniqueConstraint(columnNames = "STOCK_NAME"),
            @UniqueConstraint(columnNames = "STOCK_CODE") })
@Id
      @GeneratedValue(strategy = IDENTITY)
      @Column(name = "STOCK_ID", unique = true, nullable = false)

@OneToOne(fetch = FetchType.LAZY, mappedBy = "stock", cascade = CascadeType.ALL)



@GenericGenerator(name = "generator", strategy = "foreign",
      parameters = @Parameter(name = "property", value = "stock"))
      @Id
      @GeneratedValue(generator = "generator")
      @Column(name = "STOCK_ID", unique = true, nullable = false)



what is meaning of these annotations.
Please advice
This is how the Code entities are mapped to the Database fields, the DB Constraints and how the primary ID are generated.