JPA composite primary key/foreign key mapping












0















I have 2 table like



enter image description here



then i try to mapping with using @Embeddable like This reference



Week_Effort.java



@Entity 
@IdClass(Week_Effort.class)
@Table(name = "week_effort")
public class Week_Effort implements Serializable {

private static final long serialVersionUID = -2825819221813101109L;

@Id
@Column(name="week_id")
private int week_id;

@Id
@Column(name="timesheet_id")
private int timesheet_id;

@Column(name="day1")
private int day1;

@ManyToOne(fetch = FetchType.LAZY ,cascade=CascadeType.ALL)
@JoinColumn(name="timesheet_id" , referencedColumnName = "timesheet_id",insertable=false, updatable=false , foreignKey = @ForeignKey(name = "fkweekts"))
private Timesheet timesheet_id ;
.
.
.
//get and set
}


Timesheet.java



@Entity
@Table(name = "timesheet")
public class Timesheet implements Serializable{

private static final long serialVersionUID = 7014333990749288304L;

@GeneratedValue(strategy = GenerationType.IDENTITY)
@Id
@Column(name = "timesheet_id")
private int timesheet_id;

@OneToMany(mappedBy="timesheet_id" , cascade=CascadeType.ALL)
private Set<Week_Effort> weekeffort ;
.
.
.
//get and set

}


WeekEmbed.java



@Embeddable
public class WeekEmbed implements Serializable {

private static final long serialVersionUID = 3229945076116848141L;

int timesheet_id;
int week_id;

//get set

}


I use AJAX to post parameter as json like



{"timesheet_id":1,"day1":"8"} //and more 6 parameter


week_id generate by some process and then set it before add with CRUD in Jparepository.But error



java.sql.SQLException: Parameter index out of range (10 > number of parameters, which is 9)


How to fix this? What I'm doing wrong here?










share|improve this question























  • What is this about? foreignKey = @ForeignKey(name = "fkweekts")

    – K.Nicholas
    Nov 20 '18 at 3:44











  • it's just naming for FK . not effective to code. @K.Nicholas

    – I3eaver
    Nov 20 '18 at 3:50













  • I don't see you need such a thing. You should start with a much simpler setup - no @JoinColumn annotation and get that working first. I don't even see where you think you are using your composite key.

    – K.Nicholas
    Nov 20 '18 at 3:52
















0















I have 2 table like



enter image description here



then i try to mapping with using @Embeddable like This reference



Week_Effort.java



@Entity 
@IdClass(Week_Effort.class)
@Table(name = "week_effort")
public class Week_Effort implements Serializable {

private static final long serialVersionUID = -2825819221813101109L;

@Id
@Column(name="week_id")
private int week_id;

@Id
@Column(name="timesheet_id")
private int timesheet_id;

@Column(name="day1")
private int day1;

@ManyToOne(fetch = FetchType.LAZY ,cascade=CascadeType.ALL)
@JoinColumn(name="timesheet_id" , referencedColumnName = "timesheet_id",insertable=false, updatable=false , foreignKey = @ForeignKey(name = "fkweekts"))
private Timesheet timesheet_id ;
.
.
.
//get and set
}


Timesheet.java



@Entity
@Table(name = "timesheet")
public class Timesheet implements Serializable{

private static final long serialVersionUID = 7014333990749288304L;

@GeneratedValue(strategy = GenerationType.IDENTITY)
@Id
@Column(name = "timesheet_id")
private int timesheet_id;

@OneToMany(mappedBy="timesheet_id" , cascade=CascadeType.ALL)
private Set<Week_Effort> weekeffort ;
.
.
.
//get and set

}


WeekEmbed.java



@Embeddable
public class WeekEmbed implements Serializable {

private static final long serialVersionUID = 3229945076116848141L;

int timesheet_id;
int week_id;

//get set

}


I use AJAX to post parameter as json like



{"timesheet_id":1,"day1":"8"} //and more 6 parameter


week_id generate by some process and then set it before add with CRUD in Jparepository.But error



java.sql.SQLException: Parameter index out of range (10 > number of parameters, which is 9)


How to fix this? What I'm doing wrong here?










share|improve this question























  • What is this about? foreignKey = @ForeignKey(name = "fkweekts")

    – K.Nicholas
    Nov 20 '18 at 3:44











  • it's just naming for FK . not effective to code. @K.Nicholas

    – I3eaver
    Nov 20 '18 at 3:50













  • I don't see you need such a thing. You should start with a much simpler setup - no @JoinColumn annotation and get that working first. I don't even see where you think you are using your composite key.

    – K.Nicholas
    Nov 20 '18 at 3:52














0












0








0








I have 2 table like



enter image description here



then i try to mapping with using @Embeddable like This reference



Week_Effort.java



@Entity 
@IdClass(Week_Effort.class)
@Table(name = "week_effort")
public class Week_Effort implements Serializable {

private static final long serialVersionUID = -2825819221813101109L;

@Id
@Column(name="week_id")
private int week_id;

@Id
@Column(name="timesheet_id")
private int timesheet_id;

@Column(name="day1")
private int day1;

@ManyToOne(fetch = FetchType.LAZY ,cascade=CascadeType.ALL)
@JoinColumn(name="timesheet_id" , referencedColumnName = "timesheet_id",insertable=false, updatable=false , foreignKey = @ForeignKey(name = "fkweekts"))
private Timesheet timesheet_id ;
.
.
.
//get and set
}


Timesheet.java



@Entity
@Table(name = "timesheet")
public class Timesheet implements Serializable{

private static final long serialVersionUID = 7014333990749288304L;

@GeneratedValue(strategy = GenerationType.IDENTITY)
@Id
@Column(name = "timesheet_id")
private int timesheet_id;

@OneToMany(mappedBy="timesheet_id" , cascade=CascadeType.ALL)
private Set<Week_Effort> weekeffort ;
.
.
.
//get and set

}


WeekEmbed.java



@Embeddable
public class WeekEmbed implements Serializable {

private static final long serialVersionUID = 3229945076116848141L;

int timesheet_id;
int week_id;

//get set

}


I use AJAX to post parameter as json like



{"timesheet_id":1,"day1":"8"} //and more 6 parameter


week_id generate by some process and then set it before add with CRUD in Jparepository.But error



java.sql.SQLException: Parameter index out of range (10 > number of parameters, which is 9)


How to fix this? What I'm doing wrong here?










share|improve this question














I have 2 table like



enter image description here



then i try to mapping with using @Embeddable like This reference



Week_Effort.java



@Entity 
@IdClass(Week_Effort.class)
@Table(name = "week_effort")
public class Week_Effort implements Serializable {

private static final long serialVersionUID = -2825819221813101109L;

@Id
@Column(name="week_id")
private int week_id;

@Id
@Column(name="timesheet_id")
private int timesheet_id;

@Column(name="day1")
private int day1;

@ManyToOne(fetch = FetchType.LAZY ,cascade=CascadeType.ALL)
@JoinColumn(name="timesheet_id" , referencedColumnName = "timesheet_id",insertable=false, updatable=false , foreignKey = @ForeignKey(name = "fkweekts"))
private Timesheet timesheet_id ;
.
.
.
//get and set
}


Timesheet.java



@Entity
@Table(name = "timesheet")
public class Timesheet implements Serializable{

private static final long serialVersionUID = 7014333990749288304L;

@GeneratedValue(strategy = GenerationType.IDENTITY)
@Id
@Column(name = "timesheet_id")
private int timesheet_id;

@OneToMany(mappedBy="timesheet_id" , cascade=CascadeType.ALL)
private Set<Week_Effort> weekeffort ;
.
.
.
//get and set

}


WeekEmbed.java



@Embeddable
public class WeekEmbed implements Serializable {

private static final long serialVersionUID = 3229945076116848141L;

int timesheet_id;
int week_id;

//get set

}


I use AJAX to post parameter as json like



{"timesheet_id":1,"day1":"8"} //and more 6 parameter


week_id generate by some process and then set it before add with CRUD in Jparepository.But error



java.sql.SQLException: Parameter index out of range (10 > number of parameters, which is 9)


How to fix this? What I'm doing wrong here?







java hibernate jpa






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 20 '18 at 2:51









I3eaverI3eaver

124




124













  • What is this about? foreignKey = @ForeignKey(name = "fkweekts")

    – K.Nicholas
    Nov 20 '18 at 3:44











  • it's just naming for FK . not effective to code. @K.Nicholas

    – I3eaver
    Nov 20 '18 at 3:50













  • I don't see you need such a thing. You should start with a much simpler setup - no @JoinColumn annotation and get that working first. I don't even see where you think you are using your composite key.

    – K.Nicholas
    Nov 20 '18 at 3:52



















  • What is this about? foreignKey = @ForeignKey(name = "fkweekts")

    – K.Nicholas
    Nov 20 '18 at 3:44











  • it's just naming for FK . not effective to code. @K.Nicholas

    – I3eaver
    Nov 20 '18 at 3:50













  • I don't see you need such a thing. You should start with a much simpler setup - no @JoinColumn annotation and get that working first. I don't even see where you think you are using your composite key.

    – K.Nicholas
    Nov 20 '18 at 3:52

















What is this about? foreignKey = @ForeignKey(name = "fkweekts")

– K.Nicholas
Nov 20 '18 at 3:44





What is this about? foreignKey = @ForeignKey(name = "fkweekts")

– K.Nicholas
Nov 20 '18 at 3:44













it's just naming for FK . not effective to code. @K.Nicholas

– I3eaver
Nov 20 '18 at 3:50







it's just naming for FK . not effective to code. @K.Nicholas

– I3eaver
Nov 20 '18 at 3:50















I don't see you need such a thing. You should start with a much simpler setup - no @JoinColumn annotation and get that working first. I don't even see where you think you are using your composite key.

– K.Nicholas
Nov 20 '18 at 3:52





I don't see you need such a thing. You should start with a much simpler setup - no @JoinColumn annotation and get that working first. I don't even see where you think you are using your composite key.

– K.Nicholas
Nov 20 '18 at 3:52












1 Answer
1






active

oldest

votes


















0














From :Hibernate: Parameter index out of range (8 > number of parameters, which is 7)



I change @IdClass to WeekEmbed.class and delete some part then add @Id to object mapping.



Week_Effort.java



@Entity 
@IdClass(WeekEmbed.class)
@Table(name = "week_effort")
public class Week_Effort implements Serializable {

private static final long serialVersionUID = -2825819221813101109L;

@Id
@Column(name="week_id")
private int week_id;

//Delete this part
//@Id
//@Column(name="timesheet_id")
//private int timesheet_id;

@Column(name="day1")
private int day1;

@Id
@ManyToOne(fetch = FetchType.LAZY )
@JoinColumn(name="timesheet_id" , referencedColumnName = "timesheet_id",insertable=false, updatable=false , foreignKey = @ForeignKey(name = "fkweekts"))
private Timesheet timesheet_id ;
.
.
.
//get and set
}





share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53385521%2fjpa-composite-primary-key-foreign-key-mapping%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    From :Hibernate: Parameter index out of range (8 > number of parameters, which is 7)



    I change @IdClass to WeekEmbed.class and delete some part then add @Id to object mapping.



    Week_Effort.java



    @Entity 
    @IdClass(WeekEmbed.class)
    @Table(name = "week_effort")
    public class Week_Effort implements Serializable {

    private static final long serialVersionUID = -2825819221813101109L;

    @Id
    @Column(name="week_id")
    private int week_id;

    //Delete this part
    //@Id
    //@Column(name="timesheet_id")
    //private int timesheet_id;

    @Column(name="day1")
    private int day1;

    @Id
    @ManyToOne(fetch = FetchType.LAZY )
    @JoinColumn(name="timesheet_id" , referencedColumnName = "timesheet_id",insertable=false, updatable=false , foreignKey = @ForeignKey(name = "fkweekts"))
    private Timesheet timesheet_id ;
    .
    .
    .
    //get and set
    }





    share|improve this answer




























      0














      From :Hibernate: Parameter index out of range (8 > number of parameters, which is 7)



      I change @IdClass to WeekEmbed.class and delete some part then add @Id to object mapping.



      Week_Effort.java



      @Entity 
      @IdClass(WeekEmbed.class)
      @Table(name = "week_effort")
      public class Week_Effort implements Serializable {

      private static final long serialVersionUID = -2825819221813101109L;

      @Id
      @Column(name="week_id")
      private int week_id;

      //Delete this part
      //@Id
      //@Column(name="timesheet_id")
      //private int timesheet_id;

      @Column(name="day1")
      private int day1;

      @Id
      @ManyToOne(fetch = FetchType.LAZY )
      @JoinColumn(name="timesheet_id" , referencedColumnName = "timesheet_id",insertable=false, updatable=false , foreignKey = @ForeignKey(name = "fkweekts"))
      private Timesheet timesheet_id ;
      .
      .
      .
      //get and set
      }





      share|improve this answer


























        0












        0








        0







        From :Hibernate: Parameter index out of range (8 > number of parameters, which is 7)



        I change @IdClass to WeekEmbed.class and delete some part then add @Id to object mapping.



        Week_Effort.java



        @Entity 
        @IdClass(WeekEmbed.class)
        @Table(name = "week_effort")
        public class Week_Effort implements Serializable {

        private static final long serialVersionUID = -2825819221813101109L;

        @Id
        @Column(name="week_id")
        private int week_id;

        //Delete this part
        //@Id
        //@Column(name="timesheet_id")
        //private int timesheet_id;

        @Column(name="day1")
        private int day1;

        @Id
        @ManyToOne(fetch = FetchType.LAZY )
        @JoinColumn(name="timesheet_id" , referencedColumnName = "timesheet_id",insertable=false, updatable=false , foreignKey = @ForeignKey(name = "fkweekts"))
        private Timesheet timesheet_id ;
        .
        .
        .
        //get and set
        }





        share|improve this answer













        From :Hibernate: Parameter index out of range (8 > number of parameters, which is 7)



        I change @IdClass to WeekEmbed.class and delete some part then add @Id to object mapping.



        Week_Effort.java



        @Entity 
        @IdClass(WeekEmbed.class)
        @Table(name = "week_effort")
        public class Week_Effort implements Serializable {

        private static final long serialVersionUID = -2825819221813101109L;

        @Id
        @Column(name="week_id")
        private int week_id;

        //Delete this part
        //@Id
        //@Column(name="timesheet_id")
        //private int timesheet_id;

        @Column(name="day1")
        private int day1;

        @Id
        @ManyToOne(fetch = FetchType.LAZY )
        @JoinColumn(name="timesheet_id" , referencedColumnName = "timesheet_id",insertable=false, updatable=false , foreignKey = @ForeignKey(name = "fkweekts"))
        private Timesheet timesheet_id ;
        .
        .
        .
        //get and set
        }






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 20 '18 at 4:01









        I3eaverI3eaver

        124




        124






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53385521%2fjpa-composite-primary-key-foreign-key-mapping%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            MongoDB - Not Authorized To Execute Command

            How to fix TextFormField cause rebuild widget in Flutter

            in spring boot 2.1 many test slices are not allowed anymore due to multiple @BootstrapWith