Hibernate, insert or update without select

后端 未结 3 1416
温柔的废话
温柔的废话 2021-02-20 05:51

I have a products objects which belongs to certain categories i.e. classical many to one relationship.

@Entity
public class Product{

    @Id
    @GeneratedValue         


        
3条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-02-20 05:52

    I've just tried following:

    Category category = new Category(categoryId);
    product.setCategory(category);
    

    And it worked, i mean product record in db got correct link to category and category with id

    categoryId
    

    haven't changed.

提交回复
热议问题