-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 10 posts ] 
Author Message
 Post subject: Duplicated @RevisionEntity on project with > 1 hiber config
PostPosted: Thu Nov 09, 2017 8:53 am 
Newbie

Joined: Thu Nov 09, 2017 8:47 am
Posts: 8
Hi!

Please bear with me for explanation on issue, it starts as a common one, but it's not quite that

I have a project which has its own set of entities that come from two different schemas, they both use the same UserRevEntity in order to save audited entries, so up to there it's fine. I also need to bring in two projects that have their own persistence schemas and bring data from separate DBs, obviously, they have their own UserRevEntity to save audited entries in the schemas.

So, this was working fine on version 4.3.6, but since trying to migrate to version 5.2.8, it just won't work, it complains about having more than one entity with @RevisionEntity annotation.

I'm using JPA and Hibernate, so I don't have a hibernate.cfg.xml file

Any help will be very, very appreciated

EDIT adding code as requested by first reply:

The code for the class on the dependency:

Code:
package org.wwarn.chassis.server;

import org.hibernate.envers.RevisionEntity;
import org.hibernate.envers.RevisionNumber;
import org.hibernate.envers.RevisionTimestamp;

import javax.persistence.*;

/**
* Created by suay on 12/16/15.
*/
@Entity
@Table(name = "REVINFOUSER", schema = "chassisCore")
@RevisionEntity(UserRevisionListener.class)
public class UserRevEntity {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @RevisionNumber
    private int id;

    @RevisionTimestamp
    private long timestamp;

    private String username;

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }


    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (!(o instanceof UserRevEntity)) return false;

        UserRevEntity that = (UserRevEntity) o;

        if (id != that.id) return false;
        if (timestamp != that.timestamp) return false;
        if (username != null ? !username.equals(that.username) : that.username != null) return false;

        return true;
    }

    @Override
    public int hashCode() {
        int result = id;
        result = 31 * result + (int) (timestamp ^ (timestamp >>> 32));
        result = 31 * result + (username != null ? username.hashCode() : 0);
        return result;
    }

    @Override
    public String toString() {
        return "UserRevEntity{" +
                "id=" + id +
                ", timestamp=" + timestamp +
                ", username='" + username + '\'' +
                '}';
    }
}


The code for the class on the actual project:

Code:
package org.wwarn.config.envers;

import org.hibernate.envers.DefaultRevisionEntity;
import org.hibernate.envers.RevisionEntity;
import org.hibernate.envers.RevisionNumber;
import org.hibernate.envers.RevisionTimestamp;

import javax.persistence.*;

/**
* Created by suay on 3/22/16.
*/
@Entity
@Table(name = "UserRevEntity", catalog = "molecular")
@RevisionEntity(UserRevisionListener.class)
public class UserRevEntity {

    @Id
    @GeneratedValue(strategy= GenerationType.IDENTITY)
    @RevisionNumber
    private int id;

    @RevisionTimestamp
    private long timestamp;

    private String username;
    public String getUsername() { return username; }
    public void setUsername(String username) { this.username = username; }


    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (!(o instanceof UserRevEntity)) return false;

        UserRevEntity that = (UserRevEntity) o;

        if (id != that.id) return false;
        if (timestamp != that.timestamp) return false;
        if (username != null ? !username.equals(that.username) : that.username != null) return false;

        return true;
    }

    @Override
    public int hashCode() {
        int result = id;
        result = 31 * result + (int) (timestamp ^ (timestamp >>> 32));
        result = 31 * result + (username != null ? username.hashCode() : 0);
        return result;
    }

    @Override
    public String toString() {
        return "UserRevEntity{" +
            "id=" + id +
            ", timestamp=" + timestamp +
            ", username='" + username + '\'' +
            '}';
    }
}


The error I get at the first go is:

Code:
Only one entity may be annotated with @RevisionEntity


If I delete the @RevisionEntity annotation I get the following:
Code:
org.hibernate.MappingException: Repeated column in mapping for entity: StudyEntity_FileEntity_AUD column: file_id (should be mapped with insert="false" update="false")


However if I add insertable = false and updatable = false it insists with same error

If I change the name of the UserRevEntity class on the project, I get the original error too


Last edited by stevenGarcia on Thu Nov 09, 2017 9:41 am, edited 3 times in total.

Top
 Profile  
 
 Post subject: Re: Duplicated @RevisionEntity on project with > 1 hiber config
PostPosted: Thu Nov 09, 2017 9:00 am 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1628
Location: Romania
You need to add some code examples with your entities to have a better idea of what you try to do. You can try to isolate it with our templates if you suspect some bug.


Top
 Profile  
 
 Post subject: Re: Duplicated @RevisionEntity on project with > 1 hiber config
PostPosted: Thu Nov 09, 2017 9:39 am 
Newbie

Joined: Thu Nov 09, 2017 8:47 am
Posts: 8
vlad wrote:
You can try to isolate it with our templates if you suspect some bug.


I've had a quick look, but my example is a bit too big, as to recreate this I'd need to add imported dependencies that come from internal apps we have only on our servers, I've tried by just uploading the conflicting classes and errors, hope that will do :)


Top
 Profile  
 
 Post subject: Re: Duplicated @RevisionEntity on project with > 1 hiber config
PostPosted: Fri Nov 10, 2017 8:46 am 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1628
Location: Romania
Quote:
Only one entity may be annotated with @RevisionEntity


As we explained in the User Guide:

Quote:
It is an error for there to be multiple entities marked as @org.hibernate.envers.RevisionEntity


If that was working in 4.3.6, it was wrong since all entities must use the same RevisionEntity. All entities will have the same structure in the audit log table and the structure is defined by the RevisionEntity.


Top
 Profile  
 
 Post subject: Re: Duplicated @RevisionEntity on project with > 1 hiber config
PostPosted: Fri Nov 10, 2017 12:43 pm 
Newbie

Joined: Thu Nov 09, 2017 8:47 am
Posts: 8
Hi Vlad, I probably didn't explain myself correctly

The only reason why there are more than one RevUserEntity is because they are separate apps, surely Hibernate must be able to handle the fact that an application which uses JPA can be using as a dependency another one/more than one that also use/s JPA, but reads data from a whole different schema?

Not only did this work seamlessly on version 4.3.6, it still does!! I've only updated on local branch, master branch is still using 4.3.6 and works just fine


Top
 Profile  
 
 Post subject: Re: Duplicated @RevisionEntity on project with > 1 hiber config
PostPosted: Fri Nov 10, 2017 1:44 pm 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1628
Location: Romania
Then, try separating the SessionFactories and the JPA class scanning so that they don't conflict.


Top
 Profile  
 
 Post subject: Re: Duplicated @RevisionEntity on project with > 1 hiber config
PostPosted: Mon Nov 13, 2017 6:44 am 
Newbie

Joined: Thu Nov 09, 2017 8:47 am
Posts: 8
Hi Vlad, thank you for your reply. Could you point me in the right direction to find a guide / ideas of how to apply the steps you suggest? I've been searching and can't find anything when not using .xml configs


Top
 Profile  
 
 Post subject: Re: Duplicated @RevisionEntity on project with > 1 hiber config
PostPosted: Mon Nov 13, 2017 8:31 am 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1628
Location: Romania
You just have to specify the mappings in each persistence.xml either via the <class> or <mapping-file> elements. It's as easy as that.


Top
 Profile  
 
 Post subject: Re: Duplicated @RevisionEntity on project with > 1 hiber config
PostPosted: Mon Nov 13, 2017 8:47 am 
Newbie

Joined: Thu Nov 09, 2017 8:47 am
Posts: 8
Hi Vlad

That's already been done in a cfg.xml for the dependency project:

Code:
<hibernate-configuration>
    <session-factory>
        <property name="hibernate.dialect">org.hibernate.dialect.MySQL5Dialect</property>
        <property name="connection.url">jdbc:mysql://localhost:3306/db</property>
        <property name="connection.driver_class">com.mysql.jdbc.Driver</property>
        <property name="connection.username">whateveer</property>
        <property name="connection.password">whatever</property>
        <property name="connection.provider_class">
            org.hibernate.c3p0.internal.C3P0ConnectionProvider
        </property>
        <property name="hibernate.c3p0.acquire_increment">1</property>
        <property name="hibernate.c3p0.idle_test_period">60</property>
        <property name="hibernate.c3p0.min_size">1</property>
        <property name="hibernate.c3p0.max_size">10</property>
        <property name="hibernate.c3p0.max_statements">50</property>
        <property name="hibernate.c3p0.timeout">0</property>
        <property name="hibernate.c3p0.acquireRetryAttempts">1</property>
        <property name="hibernate.c3p0.acquireRetryDelay">250</property>
        <property name="hibernate.show_sql">true</property>
        <property name="hibernate.use_sql_comments">false</property>
        <property name="hibernate.id.new_generator_mappings">true</property>
        <property name="hibernate.current_session_context_class">thread</property>
        <property name="hibernate.enable_lazy_load_no_trans">false</property>
        <property name="hibernate.connection.autocommit">true</property>
        <property name="hbm2ddl.auto">update</property>
        <property name="hibernate.session_factory_name">session2</property>
        <mapping class="org.wwarn.chassis.server.UserRevEntity"/>
        <mapping class='org.wwarn.chassis.server.data.TosEntity'/>
        <mapping class='org.wwarn.chassis.server.data.StudyEntity'/>
        <mapping class='org.wwarn.chassis.server.data.RegimenEntity'/>
        <mapping class='org.wwarn.chassis.server.data.DrugEntity'/>
        <mapping class='org.wwarn.chassis.server.data.ActiveIngredientEntity'/>
        <mapping class='org.wwarn.chassis.server.data.DrugBatchEntity'/>
        <mapping class='org.wwarn.chassis.server.data.DosingEntity'/>
        <mapping class='org.wwarn.chassis.server.data.AdministratorEntity'/>
        <mapping class='org.wwarn.chassis.server.data.AnalyteEntity'/>
        <mapping class='org.wwarn.chassis.server.data.PublicationEntity'/>
        <mapping class='org.wwarn.chassis.server.data.PublicationReferenceEntity'/>
        <mapping class='org.wwarn.chassis.server.data.ResearcherEntity'/>
        <mapping class='org.wwarn.chassis.server.data.InstitutionEntity'/>
        <mapping class='org.wwarn.chassis.server.data.FileEntity'/>
        <mapping class='org.wwarn.chassis.server.data.ModuleEntity'/>
        <mapping class='org.wwarn.chassis.server.data.StudyGroupEntity'/>
    </session-factory>
</hibernate-configuration>


With domain entities for the main project, such as:

Code:
@Entity
@Table(name = "k13_validated_mutations", schema = "molecular")
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
@Audited
public class K13Mutation implements Serializable {

    @Id
    @Column(name = "id")
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;


Top
 Profile  
 
 Post subject: Re: Duplicated @RevisionEntity on project with > 1 hiber config
PostPosted: Mon Nov 13, 2017 10:18 am 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1628
Location: Romania
You need multiple hibernate.cfg.xml and configure each SessionFactory to take the right configuration file:

Code:
StandardServiceRegistry ssr1 = new StandardServiceRegistryBuilder()
.configure( "hibernate-module1.cfg.xml" )
.build();

....



Code:
StandardServiceRegistry ssr2 = new StandardServiceRegistryBuilder()
.configure( "hibernate-module2.cfg.xml" )
.build();

....


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 10 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.