Announcement Announcement Module
Collapse
No announcement yet.
Get DataSource from persistance-unit definition Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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
    Any ideas anyone?

    Comment


    • #3
      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();
      }

      Comment

      Working...
      X