Code Monkey home page Code Monkey logo

Comments (7)

odrotbohm avatar odrotbohm commented on May 18, 2024 1

The EnversRepositoryFactoryBean already exposes a property to customize the revision entity class. If this property is set the ReflectionRevisionEntityInformation information will be used. So the problem currently is that the infrastructure does not know about your special RevEntity class, and the namespace configuration you probably use does not expose the property. You should be able to workaround the issue by extending EnversRepositoryFactoryBean as follows:

public class CustomEnversRevisionRepositoryFactoryBean extends EnversRevisionRepositoryFactoryBean {
  public FooCustomEnversRevisionRepositoryFactoryBean() {
    setRevisionEntityClass(RevEntity.class);
  }
}

then you can alter your Spring Data JPA config as follows:

<jpa:repositories base-package="" factory-class="….CustomEnversRevisionRepositoryFactoryBean" />

We'll probably add a custom <envers:repositories /> element to the Spring Data Envers project that will expose the revision entity class attribute directly to ease the setup.

from spring-data-envers.

odrotbohm avatar odrotbohm commented on May 18, 2024 1

We just created #289.

from spring-data-envers.

raoulk avatar raoulk commented on May 18, 2024

Thnx, extending is a good idea.
I was already wondering how to use the setRevisionEntityClass()-Method in the EnversRepositoryFactoryBean, as it is not used as a plain bean ref but as a factory-class....

from spring-data-envers.

dk2k avatar dk2k commented on May 18, 2024

public class CustomEnversRevisionRepositoryFactoryBean extends EnversRevisionRepositoryFactoryBean { public FooCustomEnversRevisionRepositoryFactoryBean() { setRevisionEntityClass(RevEntity.class); } }

In the version of hibernate-envers 5.1.1.Final and spring-data-envers 1.1.15.RELEASE this code doesn't work since EnversRevisionRepositoryFactoryBean has no default constructor (and keeping in mind that "Foo" in constructor name is a typo).
This code worked for me:

public class CustomEnversRevisionRepositoryFactoryBean extends EnversRevisionRepositoryFactoryBean {
    public CustomEnversRevisionRepositoryFactoryBean(Class repositoryInterface) {
        super(repositoryInterface);
        setRevisionEntityClass(AbonRevision.class);
    }
}

from spring-data-envers.

scordio avatar scordio commented on May 18, 2024

We'll probably add a custom <envers:repositories /> element to the Spring Data Envers project that will expose the revision entity class attribute directly to ease the setup.

Hi @odrotbohm, I couldn't find anything about it so I guess this was never added. Is it something you would still consider or is subclassing the preferred approach?

from spring-data-envers.

odrotbohm avatar odrotbohm commented on May 18, 2024

We have no plans to extend our XML based configurations at the moment.

from spring-data-envers.

scordio avatar scordio commented on May 18, 2024

Thanks for the fast feedback!

What about something for Java config? I could imagine a custom annotation to avoid the EnversRevisionRepositoryFactoryBean custom class wired into @EnableJpaRepositories.

I'm happy to contribute if the idea is acceptable.

from spring-data-envers.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.