Hibernate - How to persist a new item in a Collection without loading the entire Collection

前端 未结 4 1404
悲哀的现实
悲哀的现实 2020-12-05 14:20

I have a collection in my model that contains a set of \'previous versions\' of my root domain object. The previous versions are therefore \'immutable\' and we will never wa

4条回答
  •  误落风尘
    2020-12-05 15:04

    I used to create a native query for this cases, like below:

        @Modifying
        @Transactional
        @Query(nativeQuery = true, value = "INSERT INTO categorytopic_topic(category_id, topic_id) VALUES (?1, ?2)")
        public void addTopic(long categoryId, long topicId);
    

    It's very fast because does not need load the collection.

提交回复
热议问题