-->
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.  [ 2 posts ] 
Author Message
 Post subject: Incorrect insert statement generated by Hibernate
PostPosted: Wed Oct 13, 2010 5:46 pm 
Newbie

Joined: Wed Oct 13, 2010 5:37 pm
Posts: 2
Hello,
I'm using JPA with Hibernate 3.5.6 as the persistence provider. I've mapped some entities using JPA annotations and I'm using database schema generated by Hibernate, but I'm encountering incorrect SQL insert statements in runtime when trying to persist on of the entities.
Here are the entitites:

Code:
@Entity
@Table( name = "Game" )
public class MatchEntity implements Match, Serializable {

    @Id
    @GeneratedValue( strategy = GenerationType.AUTO )
    private Long id;
    @ManyToOne(targetEntity=ClubEntity.class)
    private Club homeTeam;
    @ManyToOne(targetEntity=ClubEntity.class)
    private Club awayTeam;
    @ManyToMany(targetEntity=PlayerEntity.class)
    private Collection homeTeamPlayers;
    @ManyToMany(targetEntity=PlayerEntity.class)
    private Collection awayTeamPlayers;
    private String location;
    @Temporal( value = TemporalType.DATE )
    private Date dateHeldOn;

    protected MatchEntity() {
    }

    @Override
    public Club getAwayTeam() {
       return awayTeam;
    }
   //... other getters ...
}


The Player entity looks like this:
Code:
@Entity
@Table( name = "Player" )
public class PlayerEntity implements Player, Serializable {

    @Id
    @GeneratedValue( strategy = GenerationType.AUTO )
    private Long id;
    private String firstName;
    private String surname;
    @Temporal( value = TemporalType.DATE )
    private Date birthDate;
    @Column(name="pos")
    @Enumerated( EnumType.ORDINAL )
    private Position position;
    private int number;
   
    protected PlayerEntity() {
    }
   
    @Override
    public Date getBirthDate() {
        return birthDate;
    }
   // ...other getters...
}


The schema generated by Hibernate looks like this:
Code:
# create table Game (id bigint generated by default as identity (start with 1), dateHeldOn date, location varchar(255), awayTeam_id bigint, homeTeam_id bigint, primary key (id)) 
# create table Game_Player (Game_id bigint not null, homeTeamPlayers_id bigint not null, awayTeamPlayers_id bigint not null) 
# create table Player (id bigint generated by default as identity (start with 1), birthDate date, firstName varchar(255), number integer not null, pos integer, surname varchar(255), primary key (id))


When I try to persist the MatchEntity, one of the generated insert statements is incorrect. It tries to do two insert statements instead of one. The first insert is for awayTeamPlayers_id and the other is for homeTeamPlayers_id.
Code:
Hibernate: insert into Game_Player (Game_id, awayTeamPlayers_id) values (?, ?) 
binding '1' to parameter: 1 
binding '2' to parameter: 2 
SQL Error: 0, SQLState: null 
failed batch


Does anyone have an idea what could be wrong? I don't think that the interface types are causing this. I have specified the target entities and I also tried to get rid of the interface types and the problem just didn't go away.
I'll be grateful for any help.
Vladimir


Last edited by VladimirK on Thu Oct 14, 2010 10:31 am, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: Incorrect insert statement generated by Hibernate
PostPosted: Thu Oct 14, 2010 10:29 am 
Newbie

Joined: Wed Oct 13, 2010 5:37 pm
Posts: 2
I tried to define an explicit mapping, but the insert statements that get generated are still the same.
Code:
@Entity
@Table( name = "Game" )
public class MatchEntity implements Match, Serializable {

    @Id
    @GeneratedValue( strategy = GenerationType.AUTO )
    private Long id;
    @ManyToOne(targetEntity=ClubEntity.class)
    private Club homeTeam;
    @ManyToOne(targetEntity=ClubEntity.class)
    private Club awayTeam;
    @ManyToMany(targetEntity=PlayerEntity.class)
    @JoinTable(name="GAME_PLAYERS", joinColumns=@JoinColumn(name="MATCH_ID"),
                                    inverseJoinColumns=@JoinColumn(name="HOMEPLAYERS_ID"))
    private Collection homeTeamPlayers;
    @ManyToMany(targetEntity=PlayerEntity.class)
    @JoinTable(name="GAME_PLAYERS", joinColumns=@JoinColumn(name="MATCH_ID"),
                                    inverseJoinColumns=@JoinColumn(name="AWAYPLAYERS_ID"))
    private Collection awayTeamPlayers;
    private String location;
    @Temporal( value = TemporalType.DATE )
    private Date dateHeldOn;
...


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.