Hibernate ORM 6.0.0.Beta3 已经发布。正值假期来临之际!

我们对这次发布特别兴奋,因为它感觉像是6.0开发旅程上的最后一个Beta版本。Beta3投入了大量的工作,但就像Beta2一样,大部分工作都是在幕后。以下是一些值得注意的特定事项

@IdGeneratorType

我们定义了一种新的方法来提供自定义的IdentifierGenerator实现,并以非常类型安全的方式配置这些实现。这利用了我们终于在6.0中更多地采用的元注解。《@IdGeneratorType》应用于自定义的IdentifierGenerator实现。然后通过传递定义IdentifierGenerator配置的自定义注解(以及一些上下文细节)来实例化实现。例如,一个基于自定义序列的IdentifierGenerator可能被定义如下:

@IdGeneratorType( SimpleSequenceGenerator.class )
@Target({METHOD, FIELD})
@Retention(RUNTIME)
public @interface Sequence {
        String name();
        int startWith() default 1;
        int incrementBy() default 50;
}

class SimpleSequenceGenerator implements IdentifierGenerator {

    /**
     * The constructor signature Hibernate will use to
     * instantiate your custom generator.
     */
        public SimpleSequenceGenerator(
            Sequence configAnnotation,
            Member annotatedMember,
            CustomIdGeneratorCreationContext context) {
    }
}

@TenantId

Hibernate多年来一直支持基于单独目录和模式的多个租户。6.0增加了使用新属性@TenantId来标记定义租户的属性的方式,以使用基于列的多个租户。例如:

@Entity
public class Account {
    @Id Long id;
    @TenantId String tenantId;
    ...
}

它结合使用org.hibernate.context.spi.CurrentTenantIdentifierResolver合约来确定要使用的租户-id。

有关更多信息,请参阅[https://docs.jboss.com.cn/hibernate/orm/6.0/userguide/html_single/Hibernate_User_Guide.html#multitenacy9User](https://docs.jboss.com.cn/hibernate/orm/6.0/userguide/html_single/Hibernate_User_Guide.html#multitenacy9User)指南。

@AttributeBinderType

6.0中添加的另一个新元注解是@AttributeBinderType,它允许自定义如何定义属性映射。它声明了org.hibernate.tuple.AttributeBinder的实现,可以绑定或修改Hibernate的启动时元模型(org.hibernate.mapping包)。

这是一个非常强大且低级的方法来与Hibernate集成以实现丰富的模型。有关更多信息,请参阅[https://docs.jboss.com.cn/hibernate/orm/6.0/userguide/html_single/Hibernate_User_Guide.html#domain-customizing](https://docs.jboss.com.cn/hibernate/orm/6.0/userguide/html_single/Hibernate_User_Guide.html#domain-customizing)用户指南。

默认目录和模式

对默认目录和模式的处理已变得更加一致。请参阅https://hibernate.atlassian.net/browse/HHH-14921https://hibernate.atlassian.net/browse/HHH-14922获取详细信息。

工作在迁移指南上

随着我们越来越接近最终版本,迁移指南将变得越来越重要。我们在本次版本中投入时间使迁移指南的内容更加完善。

更多信息

请参阅用户指南迁移指南

同时,请查看发布页面

要联系,请使用在https://hibernate.com.cn/community/上讨论的常规渠道


返回顶部