I've spent all day searching for an example of this, but can't seem to find a solution.
I have recreated the problem in a simpler environment (running with a MySQL db):
2 classes, JitUser and JitGroup.
Code:
package com.digilore.model.bean;
import java.util.HashSet;
import java.util.Set;
/**
* @hibernate.class
* table="JitGroup"
*/
public class JitGroup {
private String id = null;
private String title = null;
private Set jitUsers = new HashSet();
public JitGroup() {
super();
}
/**
* @hibernate.id
* column="id"
* length="32"
* unsaved-value="null"
* generator-class="uuid.hex"
*/
public String getId() {
return id;
}
/**
* @hibernate.set
* table="JitUser_JitGroup"
* cascade="none"
* lazy="false"
* inverse="true"
* @hibernate.collection-key
* column="jitGroup"
* @hibernate.collection-many-to-many
* column="jitUser"
* class="com.digilore.model.bean.JitUser"
*/
public Set getJitUsers() {
return jitUsers;
}
/**
* @hibernate.property
* column="title"
*/
public String getTitle() {
return title;
}
public void setId(String id) {
this.id = id;
}
public void setJitUsers(Set jitUsers) {
this.jitUsers = jitUsers;
}
public void addJitUser(JitUser jitUser) {
jitUsers.add(jitUser);
jitUser.getJitGroups().add(this);
}
public void removeJitUser(JitUser jitUser) {
jitUsers.remove(jitUser);
jitUser.getJitGroups().remove(this);
}
public void setTitle(String title) {
this.title = title;
}
}
Code:
package com.digilore.model.bean;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
/**
* @hibernate.class
* table="JitUser"
*/
public class JitUser {
private String id = null;
private String userName = null;
private Set jitGroups = new HashSet();
public JitUser() {
super();
}
/**
* @hibernate.id
* column="id"
* length="32"
* unsaved-value="null"
* generator-class="uuid.hex"
*/
public String getId() {
return id;
}
/**
* @hibernate.set
* table="JitUser_JitGroup"
* cascade="none"
* lazy="false"
* inverse="false"
* @hibernate.collection-key
* column="jitUser"
* @hibernate.collection-many-to-many
* column="jitGroup"
* class="com.digilore.model.bean.JitGroup"
*/
public Set getJitGroups() {
return jitGroups;
}
/**
* @hibernate.property
* column="userName"
*/
public String getUserName() {
return userName;
}
public void setId(String id) {
this.id = id;
}
public void setJitGroups(Set jitGroups) {
this.jitGroups = jitGroups;
}
public void addJitGroup(JitGroup jitGroup) {
jitGroups.add(jitGroup);
jitGroup.getJitUsers().add(this);
}
public void removeJitGroup(JitGroup jitGroup) {
jitGroups.remove(jitGroup);
jitGroup.getJitUsers().remove(this);
}
public void setUserName(String userName) {
this.userName = userName;
}
}
Forgive me for putting my question in terms of xdoclet tags, but that's what I'm familiar with.
When I attempt to schemaexport on the generated hbm.xml's, I get the following error:
[schemaexport] create table JitUser_JitGroup (
[schemaexport] jitGroup varchar(255) not null,
[schemaexport] jitUser varchar(255) not null,
[schemaexport] primary key (jitUser, jitGroup)
[schemaexport] );
[schemaexport] (hbm2ddl.SchemaExport 154 ) Unsuccessful: create table JitUser_JitGroup (jitGroup varchar(255) not null, jitUser varchar(255) not null, primary key (jitUser, jitGroup))
[schemaexport] (hbm2ddl.SchemaExport 155 ) Invalid argument value, message from server: "Specified key was too long. Max key length is 500"
I don't understand why each column in JitUser_JitGroup is a varchar(255).
If it helps in identifying the problem, this only occurrs when I specify inverse="true" for either side.
That is, when both sides of the relationship specify inverse="false", the problem does not occur (I am aware of the run-time problem this incurs).
When inverse="false" for both sides, JitUser_JitGroup has two fields, each of which is length=32 and everything appears correct, except for the aforementioned run-time problem.
What am I doing wrong?
This can be done, right?
Any help would be appreciated.
Thanks in advance
-Trey