setAutoManyToMany

void sqlDataManager.setAutoManyToMany ( boolean enable ) (professional and enterprise editions only)

Description

Sets whether or not the data manager should automatically take care of many-to-many relationships.

Parameters

  • enable Whether the data manager should automatically run a commit for many-to-many tables when the connected tables are committed, as a boolean.

Return Values

Returns void.

Change Log

Version Description
5.0 Available for professional and enterprise editions.

If the many-to-many table has more information than just the keys then you will want to leave this feature turned off so that you can add more data than just the keys before committing.

Examples

Set Automatic Commits for Many-to-many Tables

 // Import classes
 import com.screenscraper.datamanager.*;
 import com.screenscraper.datamanager.sql.*;
 import org.apache.commons.dbcp.BasicDataSource;

 // Set Variables
 host = "127.0.0.1:3306";
 database = "mydb";
 username = "user";
 password = "pwrd";
 parameters = "autoReconnect=true&useCompression=true";

 // Build the BasicDataSource for the database connection
 BasicDataSource ds = new BasicDataSource();
 ds.setDriverClassName( "com.mysql.jdbc.Driver" );
 ds.setUsername( username );
 ds.setPassword( password );
 ds.setUrl( "jdbc:mysql://" + host + "/" + database + "?" + parameters );

 // Get MySQL datamanager
 dm = new SqlDataManager( ds, session );

 // Set Automatic Commit on Many-to-many tables
 dm.setAutoManyToMany( true );