Search in sources :

Example 1 with Owner

use of example.domain.Owner in project micronaut-sql by micronaut-projects.

the class InitController method init.

@Get
@TransactionalAdvice
void init() {
    try {
        Class.forName("net.bytebuddy.ByteBuddy");
        throw new IllegalStateException("ByteBuddy shouldn't be present on classpath");
    } catch (ClassNotFoundException e) {
    // Ignore
    }
    try {
        Class.forName("javassist.util.proxy.ProxyFactory");
        throw new IllegalStateException("Javassist shouldn't be present on classpath");
    } catch (ClassNotFoundException e) {
    // Ignore
    }
    if (LOG.isInfoEnabled()) {
        LOG.info("Running on " + System.getProperty("java.version") + " " + System.getProperty("java.vendor.version"));
        LOG.info("Populating data");
    }
    Owner fred = new Owner();
    fred.setName("Fred");
    fred.setAge(45);
    Owner barney = new Owner();
    barney.setName("Barney");
    barney.setAge(40);
    entityManager.persist(fred);
    entityManager.persist(barney);
    Pet dino = new Pet();
    dino.setName("Dino");
    dino.setOwner(fred);
    Pet bp = new Pet();
    bp.setName("Baby Puss");
    bp.setOwner(fred);
    bp.setType(Pet.PetType.CAT);
    Pet hoppy = new Pet();
    hoppy.setName("Hoppy");
    hoppy.setOwner(barney);
    entityManager.persist(dino);
    entityManager.persist(bp);
    entityManager.persist(hoppy);
}
Also used : Owner(example.domain.Owner) Pet(example.domain.Pet) TransactionalAdvice(io.micronaut.transaction.annotation.TransactionalAdvice) Get(io.micronaut.http.annotation.Get)

Example 2 with Owner

use of example.domain.Owner in project database-rider by database-rider.

the class Application method init.

@EventListener
void init(StartupEvent event) {
    if (LOG.isInfoEnabled()) {
        LOG.info("Populating data");
    }
    Owner fred = new Owner();
    fred.setName("Fred");
    fred.setAge(45);
    Owner barney = new Owner();
    barney.setName("Barney");
    barney.setAge(40);
    ownerRepository.saveAll(Arrays.asList(fred, barney));
    Pet dino = new Pet();
    dino.setName("Dino");
    dino.setOwner(fred);
    Pet bp = new Pet();
    bp.setName("Baby Puss");
    bp.setOwner(fred);
    bp.setType(PetType.CAT);
    Pet hoppy = new Pet();
    hoppy.setName("Hoppy");
    hoppy.setOwner(barney);
    petRepository.saveAll(Arrays.asList(dino, bp, hoppy));
}
Also used : Owner(example.domain.Owner) Pet(example.domain.Pet) EventListener(io.micronaut.runtime.event.annotation.EventListener)

Aggregations

Owner (example.domain.Owner)2 Pet (example.domain.Pet)2 Get (io.micronaut.http.annotation.Get)1 EventListener (io.micronaut.runtime.event.annotation.EventListener)1 TransactionalAdvice (io.micronaut.transaction.annotation.TransactionalAdvice)1