Avatar of gudii9
gudii9
Flag 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
JavaJava EEJSP

Avatar of undefined
Last Comment
Sammy

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Sammy

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
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
Sammy

This is how the Code entities are mapped to the Database fields, the DB Constraints and how the primary ID are generated.
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy