Spring Roo Project as a Transactional Batch Job

I have a Roo project that works "perfectly" with transactions, but each .merge () or .persist () takes more time and more time, so what should have taken 10 ms takes 5000 ms to the end of the transaction. Fortunately, my changes are individually idempotent, so I really don't need a transaction.

But when I throw away transaction processing, I come across the classic "The context was closed" when I do myObject.merge ()

The task that I run is from the command line in the form of a package, so this is what I usually do:

public static void main(final String[] args) {
    context = new ClassPathXmlApplicationContext("META-INF/spring/applicationContext.xml");
    JpaTransactionManager txMgr = (JpaTransactionManager) context.getBean("transactionManager");
    TransactionTemplate txTemplate = new TransactionTemplate(txMgr);
    txTemplate.execute(new TransactionCallback() { @SuppressWarnings("finally")
    public Object doInTransaction(TransactionStatus txStatus) {
    try {
        ImportUnitFromDisk importer = new ImportUnitFromDisk();
        int status = importer.run(args[0]);
        System.out.println("Import data complete status: " + status);
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        return null;
    }
    }});

    System.out.println("All done!");
    System.exit(0);
}

But I really want to do something like this:

public static void main(final String[] args) {
    ImportUnitFromDisk importer = new ImportUnitFromDisk();
    int status = importer.run(args[0]);
    System.out.println("Import data complete status: " + status);
    System.out.println("All done!");
    System.exit(0);
}

, persist() merge() , , Spring Roo ( OpenJPA MySQL)?

+3
2

, .

.

  • . (, fk refernces , )?

  • , .

  • .

  • ? , .

, Entity . ( -, ...), - . ( jpa sql, )

+1

Spring/Hibernate. , Spring Roo Spring - Hibernate/JPA.

, Hibernate Java, , ( -). Hibernate , , . , , O (n) n = # . , O (n ^ 2) .

, , ( /), , . .

. http://www.basilv.com/psd/blog/2010/avoiding-caching-to-improve-hibernate-performance.

+1

Source: https://habr.com/ru/post/1784966/


All Articles