Skip to content

Instantly share code, notes, and snippets.

@AdamBien
Created June 7, 2018 06:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AdamBien/bfa3a444b6af3316e772f8eaf133f1cb to your computer and use it in GitHub Desktop.
Save AdamBien/bfa3a444b6af3316e772f8eaf133f1cb to your computer and use it in GitHub Desktop.
52ndAirhacksQ&A.md
@gbourant
Copy link

Hello Adam,

Let's say that you are using JAX-RS and you return a Person entity that has a relation with a country.

@Entity
class Person {
    private Long id;
    private String name;
    private Country country;
}

@Entity
class Country {
    private Long id;
    private String name;
}

When i make a GET request on person entity i want to get person's details and only the country ID.
Also on POST requests i want to convert the country ID to the country POJO (country must be received from database).

  1. I would like to hear how you would approach this problem.
  2. Since i'm using Java EE 8 i tried using JSON-B (JSR 367) to achieve the functionality described above.
    2.1) What's the proper way to inject entity manager on a class that implements the JsonbDeserializer ?
    2.2) Is it possible to make a class that implements the JsonbDeserializer using generics so i wouldn't have to implement JsonbDeserializer for each entity type.

Thank you.

@rieckpil
Copy link

rieckpil commented Jun 30, 2018

Hi Adam,

I have three questions for the upcoming airhacks show:

  1. How do migrate your database schema with Flyway? Do you use the Java/Maven or CLI approach?

What do you think about the following solution (JavaEE 8, OpenLiberty 18.0.0.2, Flyway 5.0.7)?

@Startup
@TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
@Singleton
public class FlywayMigration {

    private final Logger log = Logger.getLogger(this.getClass().getName());

    @Resource(lookup = "jdbc/sample")
    DataSource dataSource;

    @PostConstruct
    private void onStartup() {

        if (dataSource == null) {
            log.severe("no datasource found to execute the db migrations!");
            throw new RuntimeException(
                    "no datasource found to execute the db migrations!");
        }

        Flyway flyway = new Flyway();
        flyway.setDataSource(dataSource);
        for (MigrationInfo i : flyway.info().all()) {
            log.info("migrate task: " + i.getVersion() + " : "
                    + i.getDescription() + " from file: " + i.getScript());
        }
        flyway.migrate();

    }
}

And what's your Flyway strategy in enterprise projects for the SQL scripts? Do you create a single SQL script for every change during the Sprint or do you collect all changes during one sprint/cycle and squash them into one single SQL script, so that /db/migration won't grow that much?

  1. What are the three most important books about Programming/Software Design/Java every developer should read in your opinion?

  2. If you could give your 20-year-old self three lessons for your Developer career, what would it be?

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment