ejb3 - blob in primary key

P

Philip Reimer

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hello all.

I'm trying to deploy a little ejb3 example application on JBoss 4.0.4 in
combination with MySql 5.0.22. In one of the entities I have a primary
key consisting of two fields, the first one is an Integer, the second
one is an Object. I've defined a key class for this compound primary key
and when I change the type of the second primary key field to String,
everything works fine, but when I leave it as an Object the creation of
the according table fails with the error message:

"BLOB/TEXT column 'windowId' used in key specification without a key length"

I found some hints on the internet that mysql requires the user to
define some kind of length for a blob that's used as a primary key, but
I'm not sure how to specify this in my source code. Didn't find any
annotation that seemed fitting. Maybe that's not even possible because
the problem lies within the object-relational mapping functionality.

Furthermore, when using the built-in hypersonic database, the
application deploys just fine in both cases (String and Object).

So, if anyone could point me in the right direction on how to solve this...
Thanks,
Philip

PS: I, of course, tried google and the jboss forums before posting here,
but to no success. Seems as if there are not many people using blobs
with ejbs, and even less using them as primary keys. Maybe it was a bad
idea in the first place?
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.4 (MingW32)

iD8DBQFEpBJ/OnXHmEVwvcQRAgHtAJ92u6QpPuiJsL0Sc/8tzqfUeXuOrACgkqS7
vkkLoJX0ztsorLReUHxflAE=
=hcMR
-----END PGP SIGNATURE-----
 
A

A.A.

Philip said:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hello all.

I'm trying to deploy a little ejb3 example application on JBoss 4.0.4 in
combination with MySql 5.0.22. In one of the entities I have a primary
key consisting of two fields, the first one is an Integer, the second
one is an Object. I've defined a key class for this compound primary key
and when I change the type of the second primary key field to String,
everything works fine, but when I leave it as an Object the creation of
the according table fails with the error message:

"BLOB/TEXT column 'windowId' used in key specification without a key length"

I found some hints on the internet that mysql requires the user to
define some kind of length for a blob that's used as a primary key, but
I'm not sure how to specify this in my source code. Didn't find any
annotation that seemed fitting. Maybe that's not even possible because
the problem lies within the object-relational mapping functionality.

Furthermore, when using the built-in hypersonic database, the
application deploys just fine in both cases (String and Object).

So, if anyone could point me in the right direction on how to solve this...
Thanks,
Philip

PS: I, of course, tried google and the jboss forums before posting here,
but to no success. Seems as if there are not many people using blobs
with ejbs, and even less using them as primary keys. Maybe it was a bad
idea in the first place?

A Blob as primary key?
This means that the DB engine has to index the Blob.
Have a look at http://dev.mysql.com/doc/refman/5.0/en/indexes.html

Personally, instead of indexing/PKing the Blob, I would generate a
hash(MD5 or whatever) from the Blob content and use it in my compound PK.

Arcadius.
 
P

Philip Reimer

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

A.A. said:
A Blob as primary key?
This means that the DB engine has to index the Blob.
Have a look at http://dev.mysql.com/doc/refman/5.0/en/indexes.html

Personally, instead of indexing/PKing the Blob, I would generate a
hash(MD5 or whatever) from the Blob content and use it in my compound PK.

Arcadius.

Hi.

Yes, I've already found that page. But how do I tell JBoss to add the
index when deploying and creating the tables? That really was my question.

But I think, I'll rather change the type back to String or so.

Thanks anyway,
Philip
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.4 (MingW32)

iD8DBQFEpN4mOnXHmEVwvcQRAnGqAJ9/+aCKqGNyKJui+hrTnLE/sD76UQCgi7JH
gpznOrMAQ4cpngULYxa2kjw=
=idSU
-----END PGP SIGNATURE-----
 
S

steve

A Blob as primary key?
This means that the DB engine has to index the Blob.
Have a look at http://dev.mysql.com/doc/refman/5.0/en/indexes.html

Personally, instead of indexing/PKing the Blob, I would generate a
hash(MD5 or whatever) from the Blob content and use it in my compound PK.

Arcadius.

personally I would not even do that.

I would add a primary key col and generate a random+the current milisec
time.

that also allows you to recover the date/time for free as well

steve
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top