I’m trying to save an array object in an entity class, which I would like to store in the GAE datastore. Sadly I get a exception, while I’m trying to initialize the array.
I get this error:
java.lang.UnsupportedOperationException: FK Arrays not supported.
My class looks like this:
@Entity
public class Game {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Key key;
...
@Persistent
private Profile[] players = new Profile[4];
...
public void setPlayers(Profile player) {
if (pcount.intValue() < 4) {
this.players[pcount] = player; //Here I get the exception
pcount = Integer.valueOf(pcount.intValue() + 1);
}
}
}
Profile
is also a entity class.
What went wrong? How could i fix this. It would be greate if someone could explain it to me!
You need to annotate your Profile
entity as @Embeddable
and in your Game
entity to annotate the players
field as @Embedded
. For detailed info on JPA annotations take a look at JPA 2 Annotations. In this way, all the Profile
fileds will be shown as inline fields of your Game
entity. If you just want to keep a reference from your Game
entity to your Profile
entities, you can use an array of Key
and not Profile
. For example,
private Key[] players = new Key[4];
Hope this helps.