Results 1 to 5 of 5

Thread: SQLITE and foreign key support

Hybrid View

  1. #1
    Join Date
    Sep 2012
    Posts
    3

    Default SQLITE and foreign key support

    Anyone had any success in getting sqlite and spring working with foreign key support enabled? By default foreign key support is disabled in sqlite. The documentation at http://www.sqlite.org/foreignkeys.html mentions that you have to enable it for each database connectiion separately. I am sure that the version of sqlite I have got supports foreign keys (downloaded it only last week).

    to test: If I key in PRAGMA foreign_keys; I get back 0. Which means foreign keys is switched off but support for it exists.

    My datasource is defined in spring as :
    <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
    <property name="driverClassName" value="${jdbc.driverclass}"/>
    <property name="url" value="${jdbc.url}"/>
    </bean>


    How do I enable foreign keys through spring configuration?

  2. #2

    Default

    Can you try adding <property name="enforceForeignKeys" value="true"/> ?

    I hope this work.

  3. #3
    Join Date
    Sep 2012
    Posts
    3

    Default

    Quote Originally Posted by m_auro1 View Post
    Can you try adding <property name="enforceForeignKeys" value="true"/> ?

    I hope this work.
    That did not work as I expected. The BasicDataSource class does not have a setter for enforceForeignKeys therefore you cannot inject it.

  4. #4

    Default

    Maybe this:

    <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
    <property name = "connectionInitSqls">
    <list><value>PRAGMA foreign_keys = ON</value></list>
    </property>
    ...
    </bean>

    Sorry but i can't try it now.

  5. #5
    Join Date
    Sep 2012
    Posts
    3

    Default

    Quote Originally Posted by m_auro1 View Post
    Maybe this:

    <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
    <property name = "connectionInitSqls">
    <list><value>PRAGMA foreign_keys = ON</value></list>
    </property>
    ...
    </bean>

    Sorry but i can't try it now.
    Thanks, that worked perfectly.

Posting Permissions

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