[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
[eclipselink-users] EclipseLink 2.4.1 - problem with indexes on n:m relations with join tables
|
Hi,
ABSTRACT
I'm using EclipseLink 2.4.1 with many different databases (some of them
with case-sensitive column names :-().
Some of these databases automatically add indexes on foreign key
columns while others do not.
Therefore I wanted to add indexes manually with the help of @Index(es)
annotations,
but do not get any indexes if N:M relations with Join Tables are used.
What's the right way to declare indexes on join tables since it seems
to be a matter of when each table is generated in the database?
The join table is not existing while the relation tables are processed
and thus no index can be created.
EXAMPLE
Here's a ManyToMany-code snippet that is *not* creating any indexes:
@Entity
public class ConfigurationEjb {
...
public static final String ID_COLUMN_NAME = "ID";
@Id
@Column(name = ID_COLUMN_NAME)
@GeneratedValue(strategy = GenerationType.SEQUENCE)
protected int id;
/** The enabled module components. */
@ManyToMany(fetch = FetchType.EAGER)
@JoinTable(name = "CONFIGURATION_MODTYPE")
@Indexes({
@Index(name = "INDX_CONF_MT_CONF_ID", table =
"CONFIGURATION_MODTYPE", columnNames = "ConfigurationEjb_ID"),
@Index(name = "INDX_CONF_MT_COMP_ID", table =
"CONFIGURATION_MODTYPE", columnNames = "enabledModuleComponents_ID")})
private Set<ModTypeEjb> enabledModuleComponents;
...
}
@Entity
public class ModTypeEjb
{
...
public static final String ID_COLUMN_NAME = "ID";
@Id
@Column(name = ID_COLUMN_NAME)
@GeneratedValue(strategy = GenerationType.SEQUENCE)
protected int id;
/**
* The name of the module type.
*/
@Column(nullable = false, unique = true)
public String name;
...
}
I verify that indexes are not created by creating the indexes manually.
If I do not get an exception (IndexAlreadyExists) I assume it was not
created,
after the persistenceManager was properly initialized.
TRIALS
Without success I
- ommitted the join table name inside of Index (yielded field not found
database exceptions),
- moved the Indexes-block from attribute to class level.
How can I let EclipseLink create 2 indexes on the N:M JoinTable?
I can manually add these indexes via SQL with:
CREATE INDEX INDX_CONF_MT_CONF_ID ON CONFIGURATION_MODTYPE
(ConfigurationEjb_ID);
CREATE INDEX INDX_CONF_MT_COMP_ID ON CONFIGURATION_MODTYPE
(enabledCheckComponents_ID);
Thanks
Phil