org.hibernate.hql.internal.ast.QuerySyntaxException: expecting OPEN, found 'from' near line 1, column 23...












-1















I have a project in Spring Boot 1.5 with mysql database. I have 2 entity class BackupOTP & OTP and I want to copy data from OTP table to BackupOTP table using HQL. For that, I have written this code.



Query query=session.createQuery("insert into BackupOTP from OTP where isExpired=:boolean");
query.setBoolean("boolean", true);
int i=query.executeUpdate();
System.err.println("i = "+i);


But I am getting this exception



org.hibernate.hql.internal.ast.QuerySyntaxException: 
expecting OPEN, found 'from' near line 1, column 23
[insert into BackupOTP from com.groupbima.central.entity.OTP where isExpired=:boolean]



How to resolve this issue?











share|improve this question

























  • why are you using where clause for insert?

    – Alien
    Nov 23 '18 at 10:02











  • It is necessary for our requirement. If OTP is expired then we need to back up otherwise we don't want to backup that's why we have taken isExpired=true

    – Altaf
    Nov 23 '18 at 10:03











  • That's not valid HQL. Here's the documentation for insert statements: docs.jboss.org/hibernate/orm/current/userguide/html_single/…. Everything becomes smpler when you read the documentation.

    – JB Nizet
    Nov 23 '18 at 10:08













  • What is the reason for down vote?

    – Altaf
    Nov 23 '18 at 11:30











  • The reason is that you asked without first doing the most basic research: read the documentation about insert statements.

    – JB Nizet
    Nov 23 '18 at 13:08
















-1















I have a project in Spring Boot 1.5 with mysql database. I have 2 entity class BackupOTP & OTP and I want to copy data from OTP table to BackupOTP table using HQL. For that, I have written this code.



Query query=session.createQuery("insert into BackupOTP from OTP where isExpired=:boolean");
query.setBoolean("boolean", true);
int i=query.executeUpdate();
System.err.println("i = "+i);


But I am getting this exception



org.hibernate.hql.internal.ast.QuerySyntaxException: 
expecting OPEN, found 'from' near line 1, column 23
[insert into BackupOTP from com.groupbima.central.entity.OTP where isExpired=:boolean]



How to resolve this issue?











share|improve this question

























  • why are you using where clause for insert?

    – Alien
    Nov 23 '18 at 10:02











  • It is necessary for our requirement. If OTP is expired then we need to back up otherwise we don't want to backup that's why we have taken isExpired=true

    – Altaf
    Nov 23 '18 at 10:03











  • That's not valid HQL. Here's the documentation for insert statements: docs.jboss.org/hibernate/orm/current/userguide/html_single/…. Everything becomes smpler when you read the documentation.

    – JB Nizet
    Nov 23 '18 at 10:08













  • What is the reason for down vote?

    – Altaf
    Nov 23 '18 at 11:30











  • The reason is that you asked without first doing the most basic research: read the documentation about insert statements.

    – JB Nizet
    Nov 23 '18 at 13:08














-1












-1








-1








I have a project in Spring Boot 1.5 with mysql database. I have 2 entity class BackupOTP & OTP and I want to copy data from OTP table to BackupOTP table using HQL. For that, I have written this code.



Query query=session.createQuery("insert into BackupOTP from OTP where isExpired=:boolean");
query.setBoolean("boolean", true);
int i=query.executeUpdate();
System.err.println("i = "+i);


But I am getting this exception



org.hibernate.hql.internal.ast.QuerySyntaxException: 
expecting OPEN, found 'from' near line 1, column 23
[insert into BackupOTP from com.groupbima.central.entity.OTP where isExpired=:boolean]



How to resolve this issue?











share|improve this question
















I have a project in Spring Boot 1.5 with mysql database. I have 2 entity class BackupOTP & OTP and I want to copy data from OTP table to BackupOTP table using HQL. For that, I have written this code.



Query query=session.createQuery("insert into BackupOTP from OTP where isExpired=:boolean");
query.setBoolean("boolean", true);
int i=query.executeUpdate();
System.err.println("i = "+i);


But I am getting this exception



org.hibernate.hql.internal.ast.QuerySyntaxException: 
expecting OPEN, found 'from' near line 1, column 23
[insert into BackupOTP from com.groupbima.central.entity.OTP where isExpired=:boolean]



How to resolve this issue?








java mysql hibernate spring-boot hql






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 23 '18 at 10:04







Altaf

















asked Nov 23 '18 at 10:00









AltafAltaf

3610




3610













  • why are you using where clause for insert?

    – Alien
    Nov 23 '18 at 10:02











  • It is necessary for our requirement. If OTP is expired then we need to back up otherwise we don't want to backup that's why we have taken isExpired=true

    – Altaf
    Nov 23 '18 at 10:03











  • That's not valid HQL. Here's the documentation for insert statements: docs.jboss.org/hibernate/orm/current/userguide/html_single/…. Everything becomes smpler when you read the documentation.

    – JB Nizet
    Nov 23 '18 at 10:08













  • What is the reason for down vote?

    – Altaf
    Nov 23 '18 at 11:30











  • The reason is that you asked without first doing the most basic research: read the documentation about insert statements.

    – JB Nizet
    Nov 23 '18 at 13:08



















  • why are you using where clause for insert?

    – Alien
    Nov 23 '18 at 10:02











  • It is necessary for our requirement. If OTP is expired then we need to back up otherwise we don't want to backup that's why we have taken isExpired=true

    – Altaf
    Nov 23 '18 at 10:03











  • That's not valid HQL. Here's the documentation for insert statements: docs.jboss.org/hibernate/orm/current/userguide/html_single/…. Everything becomes smpler when you read the documentation.

    – JB Nizet
    Nov 23 '18 at 10:08













  • What is the reason for down vote?

    – Altaf
    Nov 23 '18 at 11:30











  • The reason is that you asked without first doing the most basic research: read the documentation about insert statements.

    – JB Nizet
    Nov 23 '18 at 13:08

















why are you using where clause for insert?

– Alien
Nov 23 '18 at 10:02





why are you using where clause for insert?

– Alien
Nov 23 '18 at 10:02













It is necessary for our requirement. If OTP is expired then we need to back up otherwise we don't want to backup that's why we have taken isExpired=true

– Altaf
Nov 23 '18 at 10:03





It is necessary for our requirement. If OTP is expired then we need to back up otherwise we don't want to backup that's why we have taken isExpired=true

– Altaf
Nov 23 '18 at 10:03













That's not valid HQL. Here's the documentation for insert statements: docs.jboss.org/hibernate/orm/current/userguide/html_single/…. Everything becomes smpler when you read the documentation.

– JB Nizet
Nov 23 '18 at 10:08







That's not valid HQL. Here's the documentation for insert statements: docs.jboss.org/hibernate/orm/current/userguide/html_single/…. Everything becomes smpler when you read the documentation.

– JB Nizet
Nov 23 '18 at 10:08















What is the reason for down vote?

– Altaf
Nov 23 '18 at 11:30





What is the reason for down vote?

– Altaf
Nov 23 '18 at 11:30













The reason is that you asked without first doing the most basic research: read the documentation about insert statements.

– JB Nizet
Nov 23 '18 at 13:08





The reason is that you asked without first doing the most basic research: read the documentation about insert statements.

– JB Nizet
Nov 23 '18 at 13:08












1 Answer
1






active

oldest

votes


















0














Finally, I got the answer.




Actually, It was the problem with HQL syntax. My HQL syntax was wrong. I looked into Hibernate insert query documentation and modified my insert syntax like this




Query query=session.createQuery("insert into BackupOTP (otpId, createdTime, encryptedOTP, isExpired, updatedTime)"
+ " select otpId, createdTime, encryptedOTP, isExpired, updatedTime from OTP where isExpired=:boolean");

query.setBoolean("boolean", true);
int i=query.executeUpdate();
System.err.println("i = "+i);



Now it is working.







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%2f53444439%2forg-hibernate-hql-internal-ast-querysyntaxexception-expecting-open-found-from%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














    Finally, I got the answer.




    Actually, It was the problem with HQL syntax. My HQL syntax was wrong. I looked into Hibernate insert query documentation and modified my insert syntax like this




    Query query=session.createQuery("insert into BackupOTP (otpId, createdTime, encryptedOTP, isExpired, updatedTime)"
    + " select otpId, createdTime, encryptedOTP, isExpired, updatedTime from OTP where isExpired=:boolean");

    query.setBoolean("boolean", true);
    int i=query.executeUpdate();
    System.err.println("i = "+i);



    Now it is working.







    share|improve this answer




























      0














      Finally, I got the answer.




      Actually, It was the problem with HQL syntax. My HQL syntax was wrong. I looked into Hibernate insert query documentation and modified my insert syntax like this




      Query query=session.createQuery("insert into BackupOTP (otpId, createdTime, encryptedOTP, isExpired, updatedTime)"
      + " select otpId, createdTime, encryptedOTP, isExpired, updatedTime from OTP where isExpired=:boolean");

      query.setBoolean("boolean", true);
      int i=query.executeUpdate();
      System.err.println("i = "+i);



      Now it is working.







      share|improve this answer


























        0












        0








        0







        Finally, I got the answer.




        Actually, It was the problem with HQL syntax. My HQL syntax was wrong. I looked into Hibernate insert query documentation and modified my insert syntax like this




        Query query=session.createQuery("insert into BackupOTP (otpId, createdTime, encryptedOTP, isExpired, updatedTime)"
        + " select otpId, createdTime, encryptedOTP, isExpired, updatedTime from OTP where isExpired=:boolean");

        query.setBoolean("boolean", true);
        int i=query.executeUpdate();
        System.err.println("i = "+i);



        Now it is working.







        share|improve this answer













        Finally, I got the answer.




        Actually, It was the problem with HQL syntax. My HQL syntax was wrong. I looked into Hibernate insert query documentation and modified my insert syntax like this




        Query query=session.createQuery("insert into BackupOTP (otpId, createdTime, encryptedOTP, isExpired, updatedTime)"
        + " select otpId, createdTime, encryptedOTP, isExpired, updatedTime from OTP where isExpired=:boolean");

        query.setBoolean("boolean", true);
        int i=query.executeUpdate();
        System.err.println("i = "+i);



        Now it is working.








        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 23 '18 at 10:24









        AltafAltaf

        3610




        3610
































            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%2f53444439%2forg-hibernate-hql-internal-ast-querysyntaxexception-expecting-open-found-from%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

            "Incorrect syntax near the keyword 'ON'. (on update cascade, on delete cascade,)

            Alcedinidae

            Origin of the phrase “under your belt”?