-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 
Author Message
 Post subject: updated: unable to find logical name (SOLVED)
PostPosted: Fri Aug 31, 2007 4:12 pm 
Newbie

Joined: Thu Aug 30, 2007 4:38 am
Posts: 4
Location: Switzerland
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...


Last edited by Filot on Mon Sep 03, 2007 12:39 pm, edited 2 times in total.

Top
 Profile  
 
 Post subject: maybe a soltuion
PostPosted: Fri Aug 31, 2007 4:20 pm 
Newbie

Joined: Thu Aug 30, 2007 4:38 am
Posts: 4
Location: Switzerland
a solution would be simply to set that column acl_object_identity as an int, and put it as a foreign key for the "id" column to the acl_object_identity table...


the problem is that I didn't find how to set a field in an EJB3 as a foreign key for antoher one!


Anyone could help with this issue!?


thanks a lot!!


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 03, 2007 9:03 am 
Newbie

Joined: Thu Aug 30, 2007 4:38 am
Posts: 4
Location: Switzerland
I don't know exactly what happened, but the mentioned exception has gone.
Hibernate doesn't put a tiniy blob type for the field acl_object_identity, of course this is in the case where I don't define the constraint mentioned above.

Now, when definig the contraint, I have a new exception when deploying my application on the sever. It doesn't create the tables.

here is actually the code for the 2 EJB3 I use:



Code:
/*
* Projet : manifestation
* Créé le 31 août 2007 par hussamil
*/
package models.beans;

import java.io.Serializable;

import javax.persistence.*;

@Entity
//TODO!
@Table(name="acl_permission", uniqueConstraints ={@UniqueConstraint(columnNames = {"acl_object_identity", "recipient"})})
public class Acl_permission implements Serializable
{
   
   int id;   
   Acl_object_identity acl_object_identity;
   String recipient;
   int mask;   
   
   
   public Acl_permission(Acl_object_identity pAcl_object_identity, int pMask, String pRecipient)
   {
      super();
      // TODO Raccord de constructeur auto-généré
      acl_object_identity = pAcl_object_identity;
      mask = pMask;
      recipient = pRecipient;
   }
   
   @Id
   public int getId()
   {
      return id;
   }
   public void setId(int pId)
   {
      id = pId;
   }
   public int getMask()
   {
      return mask;
   }
   public void setMask(int pMask)
   {
      mask = pMask;
   }
   public String getRecpient()
   {
      return recipient;
   }
   public void setRecpient(String pRecpient)
   {
      recipient = pRecpient;
   }

   @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;
   }

}


Code:
/*
* Projet : manifestation
* Créé le 31 août 2007 par hussamil
*/
package models.beans;

import java.io.Serializable;

import javax.persistence.*;

@Entity
public class Acl_object_identity implements Serializable
{

   
   int id;
   String object_identity;
   Acl_object_identity parent_object;
   String  acl_class = "org.acegisecurity.acl.basic.SimpleAclEntry";
   
   
   
   public Acl_object_identity(String pObject_identity, Acl_object_identity pParent_object)
   {
      super();
      // TODO Raccord de constructeur auto-généré
      object_identity = pObject_identity;
      parent_object = pParent_object;      
   }
   
   public String getAcl_class()
   {
      return acl_class;
   }
   public void setAcl_class(String pAcl_class)
   {
      acl_class = pAcl_class;
   }
   
   @Id
   @GeneratedValue
   public int getId()
   {
      return id;
   }
   public void setId(int pId)
   {
      id = pId;
   }
   public String getObject_identity()
   {
      return object_identity;
   }
   public void setObject_identity(String pObject_identity)
   {
      object_identity = pObject_identity;
   }
   @ManyToOne
   public Acl_object_identity getParent_object()
   {
      return parent_object;
   }
   public void setParent_object(Acl_object_identity pParent_object)
   {
      parent_object = pParent_object;
   }       
   
}


The exception I have now is:

Code:

org.hibernate.MappingException: Unable to find column with logical name: acl_permission.acl_object_identity



I checked the server log, and I found something a bit strange: this exception occurs many times, even before the message of the table creation... I'm wondering if it doesn't try to find the column while he didn't create the table yet...


any ideas!? any hints are welcome!


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 03, 2007 9:31 am 
Newbie

Joined: Thu Aug 30, 2007 4:38 am
Posts: 4
Location: Switzerland
I found the error.

I should write the contraint like this:

Code:

@Table(name="acl_permission", uniqueConstraints ={@UniqueConstraint(columnNames = {"acl_object_identity_id", "recipient"})})



so the point is that I have to add "_id" to the column name, since this is how it's named at the creation!

:P

hope this helps!


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.