We help IT Professionals succeed at work.

hibernate one to one

gudii9
gudii9 asked
on
364 Views
Last Modified: 2014-05-23
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
Comment
Watch Question

CERTIFIED EXPERT
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Author

Commented:
@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
CERTIFIED EXPERT

Commented:
This is how the Code entities are mapped to the Database fields, the DB Constraints and how the primary ID are generated.
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.