Results 1 to 3 of 3

Thread: Get DataSource from persistance-unit definition

  1. #1

    Default Get DataSource from persistance-unit definition

    Hi,
    I have an existing RESOURCE_LOCAL DataSource that happens to be defined in a META-INFO/persistence.xml file

    However I need to use/inject the DataSource to a non-JPA piece of code, that just needs to get a connection from the DataSource defined there.

    How can I do this?

  2. #2

    Default

    Any ideas anyone?

  3. #3

    Default

    You should have a Datasource defined as a bean somewhere in your spring xml or java config files. Try to autowire in the datasource and get the connection from that.

    Code:
    @Autowired
    DataSource dataSource;
    
    public someMethod(){
       Connection conn = datasource.getConnection();
    }

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •