User Tools

Site Tools


hibernate

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
hibernate [2023/07/14 12:04] – [Warning: bidirectional relationships] skipidarhibernate [2023/07/14 12:42] (current) – [Transactional] skipidar
Line 224: Line 224:
  
 In Spring boot you need to annotate a method with ''@Transactional'' In Spring boot you need to annotate a method with ''@Transactional''
 +
 +At a high level, Spring creates proxies for all the classes annotated with @Transactional, either on the class or on any of the methods. The proxy allows the framework to inject transactional logic before and after the running method, mainly for starting and committing the transaction.
 +
 +https://www.baeldung.com/transaction-configuration-with-jpa-and-spring
 +
  
 https://thorben-janssen.com/transactions-spring-data-jpa/ https://thorben-janssen.com/transactions-spring-data-jpa/
Line 246: Line 251:
 </sxh> </sxh>
  
 +
 +
 +==== ManyToMany with composite key to self ====
 +
 +<sxh java>
 +
 +    @ManyToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL)
 +    @JoinTable(name="FeedsRel",
 +            joinColumns={
 +                    @JoinColumn(
 +                            name = "feedsrel_child_id",
 +                            referencedColumnName = "id"),
 +                    @JoinColumn(
 +                            name = "feedsrel_child_partitionId",
 +                            referencedColumnName = "partitionId")
 +            })
 +    private Set<Equipment> feeds = new HashSet<Equipment>();
 +
 +
 +    // Associations marked as mappedBy must not define database mappings like @JoinTable or @JoinColumn
 +    @ManyToMany( cascade = CascadeType.ALL, mappedBy="feeds", fetch = FetchType.EAGER)
 +    private Set<Equipment> fedBy = new HashSet<Equipment>();
 +</sxh>
hibernate.1689336296.txt.gz · Last modified: by skipidar