-1

We need to add additional methods to those generated classes starting with repositories and services. To do so, we create additional classes for a better migration in the future JHipster release. For example,

@Entity
public Foo {...}

@Repository
public interface FooExtendedRepository extends FooRepository {...}

@Service
public FooExtendedService extends FooService {...}

where FooExtendedService definitely needs to use FooExtendedService. There are two approaches to have it. One approach is to have FooExtendedRepository in the FooExtendedService. The other approach is to change the FooRepository attribute to FooExtendedService in the FooService class and remove the @Repository annotation from the FooRepository. The first approach is straightforward with minimum code changes, but that will double the number of instances in the system. Which approach shall we use?

1 Answer 1

1

Have a look at:

https://www.jhipster.tech/tips/035_tip_combine_generation_and_custom_code.html

Pattern-3 Side-By-Side is the prefered approach. You should be able to find a couple talks about it on Youtube.

7
  • Thanks for the information. If my understanding is correct, the side-by-side approach is to have two instances of the same type of classes for all tiers. I lean toward a single-instance approach if possible. Also, it isn't possible to have our customized logic without any code changes in the generated code. Adding a method to an enum is such example.
    – vic
    Sep 24 at 16:23
  • You can add enums to the generated code. If you also add them to your JDL file then the next time you regenerate the code they will be included. I prefer making changes to the generated files via jdl. There are minimal changes to some generated files which are reuired to make this work and that is fine.
    – jelharou
    Sep 25 at 14:14
  • Can you add a static method to an enum data type in a JDL file?
    – vic
    Sep 25 at 21:50
  • You're right in that you cannot pass a static enum method in JDL. You can always use one of the other 2 approaches: that's why the question was marked as being opinion-related...
    – jelharou
    Sep 28 at 12:25
  • Building business logic on top of JHipster generated code base is a balancing act between easy to sync up with the latest release and the best coding practice. I fail to see any benefits regarding repository and service on the side-by-side approach. Marking this question to close is heavy-handed. This attitude will damage any open-source project development.
    – vic
    Sep 28 at 16:54

Not the answer you're looking for? Browse other questions tagged or ask your own question.