<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by fong huang yee on Medium]]></title>
        <description><![CDATA[Stories by fong huang yee on Medium]]></description>
        <link>https://medium.com/@fhy?source=rss-83d2cfc2cde9------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*RBiafn_cgNZRuZsaqAhAAQ.jpeg</url>
            <title>Stories by fong huang yee on Medium</title>
            <link>https://medium.com/@fhy?source=rss-83d2cfc2cde9------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 29 Nov 2026 20:00:09 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@fhy/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Adapting GitFlow with Multiple Develop Branches]]></title>
            <link>https://medium.com/@fhy/adapting-gitflow-with-multiple-develop-branches-4c74b47f9322?source=rss-83d2cfc2cde9------2</link>
            <guid isPermaLink="false">https://medium.com/p/4c74b47f9322</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[git]]></category>
            <category><![CDATA[branching-strategy]]></category>
            <category><![CDATA[devops]]></category>
            <dc:creator><![CDATA[fong huang yee]]></dc:creator>
            <pubDate>Sun, 24 Nov 2024 10:25:29 GMT</pubDate>
            <atom:updated>2026-09-18T07:14:30.070Z</atom:updated>
            <content:encoded><![CDATA[<h3>Streamlining Releases: Adapting GitFlow with Multiple Develop Branches</h3><p>Every company adopts its own branching strategy to align with best practices. Recently, while reviewing our branching strategy, we explored models such as GitFlow, GitHub Flow, GitLab Flow, and others. Among these, GitFlow often stands out due to its popularity and flexibility, making it a common choice for many developers.</p><p>However, when we attempted to apply GitFlow, we encountered limitations, especially when managing multiple modules being developed simultaneously, each requiring independent releases regardless of the sequence.</p><p>To address this, we modified <strong>GitFlow</strong> by introducing multiple develop branches and organising feature branches under them.</p><h3>master</h3><ul><li>latest production stable version</li><li>accept PR from <strong>/</strong>rel branch after deployed to production</li><li>tag with release version</li></ul><h3>/dev</h3><ul><li>branch from <strong>master</strong></li><li>create PR to <strong>/rel</strong></li><li>accept PR from <strong>/feat</strong></li><li>naming convention /dev/m1 /dev/epic_1</li></ul><h3><strong>/feat</strong></h3><ul><li>branch from <strong>/dev</strong></li><li>create PR to <strong>/dev</strong></li><li>naming convention /feat/&lt;dev&gt;/feat_1 /feat/&lt;dev&gt;/fix_1</li></ul><h3><strong>/fix</strong></h3><ul><li>branch from <strong>master</strong></li><li>create PR to <strong>/dev</strong> or <strong>/rel</strong></li><li>naming convention /fix/fix_1 /fix/fix_2</li></ul><h3><strong>/rel</strong></h3><ul><li>branch from <strong>master</strong></li><li>accept PR from <strong>/dev</strong> or <strong>/fix</strong></li><li>create PR to <strong>master</strong> after deployed to production</li><li>version number is confirmed only after the deployment date is finalised. However, deployments may be rescheduled, using a self-descriptive name might be a more flexible option.</li><li>there’s a possibility that multiple develop branch will be included in the same release, so simply use a <em>dash</em> in the naming convention.</li><li>naming convention /rel/v1.0.0 /rel/v1.0.0-m1 /rel/epic_1-epic_2</li><li>If you need separate branches for each environment, create distinct release branches such as /rel/v1.0.0-dev /rel/v1.0.0-uat /rel/v1.0.0-prod</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4c74b47f9322" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to manage Soft Delete for Hibernate Relationships]]></title>
            <link>https://medium.com/@fhy/my-ultimate-solution-for-soft-delete-with-hibernate-d388b7b8b087?source=rss-83d2cfc2cde9------2</link>
            <guid isPermaLink="false">https://medium.com/p/d388b7b8b087</guid>
            <category><![CDATA[java]]></category>
            <category><![CDATA[hibernate]]></category>
            <category><![CDATA[spring-boot]]></category>
            <category><![CDATA[soft-delete]]></category>
            <category><![CDATA[one-to-many]]></category>
            <dc:creator><![CDATA[fong huang yee]]></dc:creator>
            <pubDate>Thu, 25 May 2023 16:13:34 GMT</pubDate>
            <atom:updated>2024-11-21T05:30:03.891Z</atom:updated>
            <content:encoded><![CDATA[<p>If you google for ‘hibernate soft delete’, you will likely come across the following implementation:</p><p><strong>@Where + @SQLDelete </strong><br>Although this approach works perfectly, it lacks the flexibility to retrieve deleted data.</p><p><strong>@FilterDef + @Filter</strong><em><br></em>You cannot enable or disable the filter for relationships like @ManyToOne. This presents a valid use case, such as when an Order has a @ManyToOne relationship with a Product, and the deleted product should still be preserved in the order. Moreover, you would need to manually enable the filter every time you start a session, which can be quite cumbersome.</p><p>Let’s consider how we typically load our data. When seeking a list of orders, querying from the Order entity, you probably wouldn’t want the deleted rows to appear in the results. Therefore, @Where + @SQLDelete actually work natively most of the time.</p><p>The challenge arises with relationships. What if we could decide whether we want the deleted relationship Product to appear in the main entity Order?</p><p>Hibernate mentioned @Where <a href="https://docs.jboss.org/hibernate/orm/6.0/javadocs/org/hibernate/annotations/Where.html">restrictions are always applied and cannot be disabled. They’re therefore much less flexible than filters</a>. However, this is not entirely accurate, as we can always override the Getter method to determine the visibility of the relationship</p><p><strong>Order</strong></p><pre><br>@Entity<br>@Table(name = “t_order”)<br>@Where(clause = “deleted = false”)<br>@SQLDelete(sql = “UPDATE t_order SET deleted = true WHERE id = ?”)<br>@EntityListeners(OrderListener.class)<br>public class Order extends BaseEntity {<br><br>  public int viewCount;<br><br>  @ManyToOne(fetch = FetchType.LAZY)<br>  private Product product;<br><br>  public Product getProduct() {<br>    return proxy(product);<br>  }<br>}</pre><p><strong>BaseEntity</strong></p><pre>@MappedSuperclass<br>public class BaseEntity implements Serializable {<br><br>    @JsonIgnore<br>    transient Logger log = LoggerFactory.getLogger(BaseEntity.class);<br><br>    @Id<br>    @GeneratedValue(strategy = IDENTITY)<br>    private long id;<br><br>    @Column(columnDefinition = &quot;boolean default false&quot;)<br>    private boolean deleted;<br><br>    protected &lt;T&gt; T proxy(T object) {<br>        try {<br>            if (object != null) {<br>                final LazyInitializer lazyInitializer = HibernateProxy.extractLazyInitializer(object);<br>                if (lazyInitializer != null) {<br>                    object = (T) Hibernate.unproxy(lazyInitializer.getSession()<br>                            .createNativeQuery(findByIdQuery(lazyInitializer), lazyInitializer.getPersistentClass())<br>                            .setParameter(&quot;id&quot;, lazyInitializer.getIdentifier())<br>                            .setFlushMode(FlushModeType.COMMIT)<br>                            .getSingleResult());<br>                    return object;<br>                }<br>            }<br>            return object;<br>        } catch (Exception e) {<br>            log.warn(&quot;Failed to load proxy {}: {}&quot;, object.getClass().getSimpleName(), e.getMessage());<br>            return null;<br>        }<br>    }<br><br>    private String findByIdQuery(LazyInitializer lazyInitializer) {<br>        EntityPersister entityPersister = lazyInitializer.getSession().getSessionFactory().getMappingMetamodel().findEntityDescriptor(lazyInitializer.getPersistentClass());<br>        String tableName = null;<br>        if (entityPersister != null &amp;&amp; entityPersister instanceof SingleTableEntityPersister)<br>            tableName = ((SingleTableEntityPersister) entityPersister).getTableName();<br>        if (!StringUtils.hasText(tableName)) {<br>            Table table = lazyInitializer.getPersistentClass().getAnnotation(Table.class);<br>            tableName = table != null ? table.name() : lazyInitializer.getPersistentClass().getSimpleName();<br>        }<br>        return &quot;SELECT * FROM &quot; + tableName + &quot; WHERE id = :id&quot;;<br>    }<br>}</pre><p>The Getter method generates a native query that selects records using the identifier without deleted = false. Consequently, we cannot utilize @JoinColumn with a non-primary key that references the @ManyToOne relationship. However, it’s worth noting that Hibernate has a <a href="https://stackoverflow.com/questions/30082281/manytoonefetch-fetchtype-lazy-doesnt-work-on-non-primary-key-referenced-co">known issue </a>where it disregards the Lazy fetch type when a non-primary key is used as the referencedColumnName. Therefore, it is generally not recommended unless there are no other alternatives.</p><p>Now, why do we need to set FlushModeType.COMMIT in the query? This is necessary because if you utilize Hibernate listeners like @PrePersist and @PreUpdate, <a href="https://stackoverflow.com/questions/42315960/stackoverflowexception-in-spring-data-jpa-app-with-spring-security-auditoraware">StackOverflowExceptions</a> may occur due to Hibernate’s dirty-detection mechanism.</p><p>Feel free to <a href="https://github.com/fonghuangyee/hibernate-soft-delete">download</a> the source code for the implementation. Additionally, you can explore the demo showcasing the final outcome.</p><ol><li>Create a new Order.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/922/1*kySaIH8wL0M8ef6-UJgRiQ.png" /></figure><p>2. After deleting the product, it remains associated with the order.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1016/1*Atu3E77oa4OpPTTOXFwmXA.png" /></figure><p>If you omit the setFlushMode(FlushModeType.COMMIT) and then attempt to retrieve the order once again, you will observe that the OrderListener is triggered over 200 times.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*61HybouN9b8PqmR_mto5Xw.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d388b7b8b087" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>