Hi all,
I would like to dynamically manage my tables in my application. I created 2 EJB3 corresponding to the two tables acl_permission and acl_object_identity.
I have a problem when trying to create the acl_persmission table:
Code:
@Entity
@Table(name="acl_permission", uniqueConstraints ={@UniqueConstraint(columnNames = {"acl_object_identity", "recipient"})})
public class Acl_permission
{
@Id
int id;
Acl_object_identity acl_object_identity;
String recipient;
int mask;
and here is when we define the relation with acl_object_identity (but this shouldn't be realted to the problem):
Code:
@OneToOne
public Acl_object_identity getAcl_object_identity()
{
return acl_object_identity;
}
public void setAcl_object_identity(Acl_object_identity pAcl_object_identity)
{
acl_object_identity = pAcl_object_identity;
}
The problem is that, when trying to create the acl_permission table, I have this exception:
Code:
2007-08-31 21:32:31,671 DEBUG [org.hibernate.tool.hbm2ddl.SchemaUpdate] create table acl_permission (id integer not null, acl_object_identity tinyblob, recipient varchar(255), mask integer not null, primary key (id), unique (acl_object_identity, recipient))
2007-08-31 21:32:31,671 ERROR [org.hibernate.tool.hbm2ddl.SchemaUpdate] Unsuccessful: create table acl_permission (id integer not null, acl_object_identity tinyblob, recipient varchar(255), mask integer not null, primary key (id), unique (acl_object_identity, recipient))
2007-08-31 21:32:31,671 ERROR [org.hibernate.tool.hbm2ddl.SchemaUpdate] BLOB/TEXT column 'acl_object_identity' used in key specification without a key length
I had a look on the net about this error, and I found an interesting link, where there is this explanation:
Quote:
The error happens because MySQL can index only the first N chars of a BLOB or TEXT column. So The error mainly happen when there is a field/column type of TEXT or BLOB or those belongs to TEXT or BLOB types such as TINYBLOB, MEDIUMBLOB, LONGBLOB, TINYTEXT, MEDIUMTEXT, and LONGTEXT that you try to make as primary key or index. With full BLOB or TEXT without the length value, MySQL is unable to guarantee the uniqueness of the column as it’s of variable and dynamic size. So, when using BLOB or TEXT types as index, the value of N must be supplied so that MySQL can determine the key length. However, MySQL doesn’t support limit on TEXT or BLOB. TEXT(88) simply won’t work.
[...]
The solution to the problem is to remove the TEXT or BLOB column from the index or unique constraint, or set another field as primary key. If you can’t do that, and wanting to place a limit on the TEXT or BLOB column, try to use VARCHAR type and place a limit of length on it. By default, VARCHAR is limited to a maximum of 255 characters and its limit must be specified implicitly within a bracket right after its declaration, i.e VARCHAR(200) will limit it to 200 characters long only.
[url]
http://www.mydigitallife.info/2007/07/0 ... ey-length/
[/url]
Anyone faced this problem before!? I don't really have an idea how to do with that...