users@glassfish.java.net

persistence - a whole series of *funky* errors

From: <glassfish_at_javadesktop.org>
Date: Wed, 08 Aug 2007 18:16:47 PDT

So anyway.

I'm running glassfish via eclipse, building a web project backed by MySql and java persistence. And it's going surprisingly well. But I am having all sorts of difficulty with java persistence annotations.

So far:
I have PLAYERs, who are identified by PLAYER.NAME. I have GAMEs, which are identified by GAME.NAME . And I have GCHARACTERs.

I had hoped that GCHARCATERs would be identified by GAME_NAME and NAME, and have a not null FK to PLAYER.

I am finding, however, that when I create a composite key class for GCHARACTER, I can't put a Game in there. Specifically, the generated tables have a GAME_NAME field, but the primary key constraint does not include it. Of course, I can put GAME_NAME in as as string - but that's not the point.

I had a look at that "Primary Key Join Column" thing, but it seems it's only for subclassing and it simply doesn't work.

So it seems that glassfish persistence prefers that all table have a simple pk generated with a sequence. I don't like it much because it breaks third normal and turns a relational database into a referenctial one, but it's acceptable as a compromise in physical design.

Next prooblem was that I wanted each table to have its own primary key class. This is a type safety issue.

Well!

First I found that if I tried to base the primary key classes on an abstract @MappedSuperClass, the ID attribute was not being persisted and the persistence engine whinged aboput tables not having any primary key classes.

Secondly, I found that if I tried to rig up a ManyToOne foreign key, the engine bitched that seing as the target table used a compound key I had to use joincolumns specifying the referenced column name, and even when I did that it just wouldn't take it.

Frankly - I am Not Happy Jan.

All this kind of stuff worked *perfectly fine* at my last contract job where we were using JBoss. But I do not want to use JBoss because the pluggable architecture blows in a number of respects.

A possibility is getting proper hibernate from hibernate.org and telling glassfish to use that as its persistence manager.

Before I go attaching files and whatnot - is anyone interested in helping with this one? Three tables, I ask you!
[Message sent by forum member 'pmurray_bigpond' (pmurray_bigpond)]

http://forums.java.net/jive/thread.jspa?messageID=230150