-->
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.  [ 1 post ] 
Author Message
 Post subject: column problem on a bidirectional one-to-many association
PostPosted: Wed Apr 12, 2006 9:42 am 
Newbie

Joined: Wed Apr 12, 2006 7:02 am
Posts: 7
Location: Southampton, UK
Hello,

I'm having some problems with a bidirectional one-to-many association where the associated entity is a joined subclass.

I have a base class called GamePrototype :

Code:
@Entity
@Inheritance(strategy = InheritanceType.JOINED)
public class GamePrototype {

    private long Id;   
    private Brand brand;

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    public long getId() {
        return id;
    }

    public void setId(long id) {
        this.id = id;
    }

    @ManyToOne
    @JoinColumn(name = "brand_id")
    public Brand getBrand() {
        return brand;
    }

    public void setBrand(Brand brand) {
        this.brand = brand;
    }
}


I have a Game class which extends GamePrototype :

Code:
@Entity
public class Game extends GamePrototype {
   
    // Some other properties in this class...
}



And I have a Brand entity which has a collection of Game objects :

Code:
@Entity
public class Brand {
   
    private long id;
    private Collection<Game> games = new HashSet();

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    public long getId() {
        return id;
    }

    public void setId(long id) {
        this.id = id;
    }

    @OneToMany(mappedBy = "brand")
    public Collection<Game> getGames() {
        return games;
    }

    public void setGames(Collection<Game> games) {
        this.games = games;
    }

}


When I try to get the collection of games back from my brand object, I get an exception because the SQL is trying to access the brand_id field on the Game table (which doesn't exist) rather than the brand_id field on the GamePrototype table.

Any help would be much appreciated,

John Pang


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

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.