Hi Roberto,

Please refer to the following application classes for a Spring Boot 
application with OrientDB JDBC Driver. This project is saving Samples, but 
if one of the Samples failed to be saved, it would not roll back and dirty 
data would be existing. Could you please advise if there is a way to 
control the transactions with this JDBC driver? Really appreciate.


*SampleApplication.java*


@SpringBootApplication

@EnableTransactionManagement

public class SampleApplication {

    @Bean

    public PlatformTransactionManager txManager(DataSource dataSource) {

        return new DataSourceTransactionManager(dataSource);

    }


    public static void main(String[] args) {

SpringApplication.run(ModuleDeviceApplication.class, args);

    }

}



*SampleDao.java*


@Service

@Transactional(propagation = Propagation.SUPPORTS, readOnly = true)

public class SampleDao {


@Autowired 

protected JdbcTemplate jdbcTemplate;


@Transactional(propagation = Propagation.REQUIRED, readOnly = false)

public void saveSamples(List<Sample> samples){

                for(Sample sample:samples){

                    String insertSql = "INSERT INTO Sample CONTENT " + 
JSON.toJSONString(sample);

                    jdbcTemplate.update(insertSql);

                }

}

}



*SampleController.java*


@RestController

public class SampleController {


    @Autowired

    private SampleDao sampleDao;


    @PostMapping("/samples/add")

    public void createSamples(@RequestBody List<Sample> samples){

         sampleDao.saveSamples(samples);

    }

}



*Sample.java*


public class Sample {

private String name;

private String status;


public String getName() {

return name;

}

public void setName(String name) {

this.name = name;

}

public String getStatus() {

return status;

}

public void setStatus(String status) {

this.status = status;

}

}



*application.yml*


server:

  port: 2266

spring:

  application:

    name: module-device

  datasource:

    url: jdbc:orient:remote:localhost/GratefulDeadConcerts

    driver-class-name: com.orientechnologies.orient.jdbc.OrientJdbcDriver

    username: admin

    password: admin

    tomcat:

      initial-size: 10

      min-idle: 5

      max-idle: 15

      max-wait: 10000

      time-between-eviction-runs-millis: 18800

      jdbc-interceptors: ConnectionState;SlowQueryReport(threshold=0)





在 2017年2月15日星期三 UTC+8下午5:53:19,Roberto Franchini写道:
>
>
>
> On Wed, 15 Feb 2017 at 10:21 Chris Wong <[email protected] <javascript:>> 
> wrote:
>
>> Hi all,
>>
>> My project is calling OrientDB with Spring JdbcTemplate through its JDBC 
>> Driver and @Transactional doesn't work. Actually, I have tried my other 
>> ways to control the transactions via OrientDB JDBC Driver, but all failed. 
>> Could you please help on this issue? As reading the user manual of 
>> OrientDB, it is transactional, but not via OrientDB JDBC Driver? Your 
>> support will be greatly appreciated on this problem.
>>
>>
> Hi, 
> I'me the maintainer of the OrientDB's JDBC Driver.
> I never tested it inside a Spring application, nor using @Transactional.
> The best way for me will be to have a minimal project, a test bed, where 
> to play to understand what is missing in the driver to be complaint.
> So, if you could share such a project with me, I'll really appreciate.
>  
>  
> -- 
> Best regards,
>  
> Roberto Franchini
>
> OrientDB LTD  -  http://orientdb.com
>

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"OrientDB" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to