相关疑难解决方法(0)

Hibernate:带有Annotations动态表名的数据对象

我有一个与表关联的Hibernate数据类; 想象这样的实体:

 @Entity
 @org.hibernate.annotations.Proxy(lazy=false)
 @Table(name="Person", schema="MySchema")
 @Inheritance(strategy=InheritanceType.SINGLE_TABLE)
 public class ProfileData implements Serializable {

    private static final long serialVersionUID = -844564646821609090L;

    public PersonData() {
    }

    @Column(name="idPerson", nullable=false, unique=true)   
    @Id 
    ...
Run Code Online (Sandbox Code Playgroud)

我需要在这个表的多年创建历史表:Person2010,Person2011,Person2012 ...是否可以不创建新的数据对象?也许通过一个参数......?我不知道.

Entity类是相同的,更改表名和构造函数.

java annotations hibernate

9
推荐指数
1
解决办法
2万
查看次数

我可以使用Liquibase创建Hibernate Envers特定表

我们的Java应用程序是基于Spring的,我们有域类和通过Liquibase生成的相应模式.

我们计划添加对要审核的单个域的支持.

一个.我们没有hibernate.xml和hibernate.cfg.xml,而是使用application-context.xml.那么如何通过@Audited等注释创建审计表.

我该如何解决这个问题?我添加了hibernate配置

<property name="hibernateProperties">
            <props>
                <prop key="hibernate.dialect">org.hibernate.dialect.MySQLInnoDBDialect</prop>
                <prop key="hibernate.ejb.event.post-insert">org.hibernate.ejb.event.EJB3PostInsertEventListener,org.hibernate.envers.event.AuditEventListener</prop>
                <prop key="hibernate.ejb.event.post-update">org.hibernate.ejb.event.EJB3PostUpdateEventListener,org.hibernate.envers.event.AuditEventListener</prop>
                <prop key="hibernate.ejb.event.post-delete">org.hibernate.ejb.event.EJB3PostDeleteEventListener,org.hibernate.envers.event.AuditEventListener</prop>
                <prop key="hibernate.ejb.event.pre-collection-update">org.hibernate.envers.event.AuditEventListener</prop>
                <!-- <prop key="hibernate.ejb.event.pre-collection-remove">org.hibernate.envers.event.AuditEventListener</prop>
                <prop key="hibernate.ejb.event.post-collection-recreate">org.hibernate.envers.event.AuditEventListener</prop> -->
                <prop key="org.hibernate.envers.revision_field_name">REV</prop>
                <prop key="org.hibernate.envers.revision_type_field_name">REVTYPE</prop>
                <prop key="org.hibernate.envers.auditTablePrefix"></prop>
                <prop key="org.hibernate.envers.auditTableSuffix">_AUD</prop>
                <prop key="hibernate.hbm2ddl.auto">update</prop>
                <prop key="hibernate.show_sql">true</prop>
            </props>
        </property>
Run Code Online (Sandbox Code Playgroud)

在我的域类中添加了@Audited注释

@Entity
@Audited
@Table(name="user")
public class User implements Serializable {
Run Code Online (Sandbox Code Playgroud)

但是此配置未在开发环境中创建审计表.我不清楚我在这里缺少什么额外的配置.

湾 如何使用Liquibase创建必要的envers特定模式,生产团队不熟悉在生产环境中自动生成SQL模式的想法.

java spring hibernate hibernate-envers

7
推荐指数
1
解决办法
1773
查看次数

标签 统计

hibernate ×2

java ×2

annotations ×1

hibernate-envers ×1

spring ×1