Eclipselink NamedNativeQuery pass column name as parameter and not a valueNull or zero primary key encountered in unit of work cloneYou have attempted to set a value of type class entityOptional or Null Parameters JPAeclipselink.query-results-cache.ignore-null not caching any resultJPA downcasting with treatIN clause with a composite primary key in JPA criteriahow to pass positional parameters to createnativequery jpa javaJPA entity with join possibly on null keyEclipseLink - The primary key read from the row during the execution of the query was detected to be null. Primary keys must not contain nullEclipselink Discriminator Column Returns NULL

Why is the name Bergson pronounced like Berksonne?

Earliest evidence of objects intended for future archaeologists?

What allows us to use imaginary numbers?

What is bodily formation? Does it refer to the breath or the body?

Is recepted a word?

My new Acer Aspire 7 doesn't have a Legacy Boot option, what can I do to get it?

Can I submit a paper computer science conference using an alias if using my real name can cause legal trouble in my original country

Vegetarian dishes on Russian trains (European part)

Is there a way to make the "o" keypress of other-window <C-x><C-o> repeatable?

Indirect speech - breaking the rules of it

How to fix Sprinkles in rendering?

How could Tony Stark wield the Infinity Nano Gauntlet - at all?

Chess software to analyze games

9 hrs long transit in DEL

!I!n!s!e!r!t! !b!e!t!w!e!e!n!

Does git delete empty folders?

Atmospheric methane to carbon

Installing the original OS X version onto a Mac?

Why should I pay for an SSL certificate?

Levenshtein Neighbours

iPad or iPhone doesn't charge until unlocked?

What's the point of writing that I know will never be used or read?

Did Wernher von Braun really have a "Saturn V painted as the V2"?

Just one file echoed from an array of files



Eclipselink NamedNativeQuery pass column name as parameter and not a value


Null or zero primary key encountered in unit of work cloneYou have attempted to set a value of type class entityOptional or Null Parameters JPAeclipselink.query-results-cache.ignore-null not caching any resultJPA downcasting with treatIN clause with a composite primary key in JPA criteriahow to pass positional parameters to createnativequery jpa javaJPA entity with join possibly on null keyEclipseLink - The primary key read from the row during the execution of the query was detected to be null. Primary keys must not contain nullEclipselink Discriminator Column Returns NULL






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








1















Trying to pass column name as parameter but JPA sets it as a value surrounding it with single quotes.



@NamedNativeQueries(
@NamedNativeQuery(
name = "Genre.findAllLocalized",
query = "SELECT "
+ " CASE "
+ " WHEN ? IS NULL THEN genre_default"
+ " ELSE ? "
+ " END localized_genre "
+ "FROM genre ORDER BY localized_genre")
)


Then:



List<String> res = em.createNamedQuery("Genre.findAllLocalized")
.setParameter(1, colName)
.setParameter(2, colName)
.getResultList();


The problem is that the column names being passed are taken as values so the result will return result list with repeated values of "col_name" instead of selecting the value of the column passed as parameter.



Is this achievable?










share|improve this question






























    1















    Trying to pass column name as parameter but JPA sets it as a value surrounding it with single quotes.



    @NamedNativeQueries(
    @NamedNativeQuery(
    name = "Genre.findAllLocalized",
    query = "SELECT "
    + " CASE "
    + " WHEN ? IS NULL THEN genre_default"
    + " ELSE ? "
    + " END localized_genre "
    + "FROM genre ORDER BY localized_genre")
    )


    Then:



    List<String> res = em.createNamedQuery("Genre.findAllLocalized")
    .setParameter(1, colName)
    .setParameter(2, colName)
    .getResultList();


    The problem is that the column names being passed are taken as values so the result will return result list with repeated values of "col_name" instead of selecting the value of the column passed as parameter.



    Is this achievable?










    share|improve this question


























      1












      1








      1








      Trying to pass column name as parameter but JPA sets it as a value surrounding it with single quotes.



      @NamedNativeQueries(
      @NamedNativeQuery(
      name = "Genre.findAllLocalized",
      query = "SELECT "
      + " CASE "
      + " WHEN ? IS NULL THEN genre_default"
      + " ELSE ? "
      + " END localized_genre "
      + "FROM genre ORDER BY localized_genre")
      )


      Then:



      List<String> res = em.createNamedQuery("Genre.findAllLocalized")
      .setParameter(1, colName)
      .setParameter(2, colName)
      .getResultList();


      The problem is that the column names being passed are taken as values so the result will return result list with repeated values of "col_name" instead of selecting the value of the column passed as parameter.



      Is this achievable?










      share|improve this question














      Trying to pass column name as parameter but JPA sets it as a value surrounding it with single quotes.



      @NamedNativeQueries(
      @NamedNativeQuery(
      name = "Genre.findAllLocalized",
      query = "SELECT "
      + " CASE "
      + " WHEN ? IS NULL THEN genre_default"
      + " ELSE ? "
      + " END localized_genre "
      + "FROM genre ORDER BY localized_genre")
      )


      Then:



      List<String> res = em.createNamedQuery("Genre.findAllLocalized")
      .setParameter(1, colName)
      .setParameter(2, colName)
      .getResultList();


      The problem is that the column names being passed are taken as values so the result will return result list with repeated values of "col_name" instead of selecting the value of the column passed as parameter.



      Is this achievable?







      eclipselink jpa-2.1






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Mar 27 at 13:50









      esteban rinconesteban rincon

      1,02511 silver badges29 bronze badges




      1,02511 silver badges29 bronze badges

























          1 Answer
          1






          active

          oldest

          votes


















          1














          Basically it makes no sense to create a prepared query like this, how would you name that query anyway: "*"? So the short answer is: no.




          1. But you could create named queries dynamically if this matches your requirement:



            String colName = "colName";
            String query = "SELECT WHEN " + colName + " IS NULL THEN genre_default";
            Query query = entitymanager.createQuery(query);



          2. Probably using a criteria builder is more the way you want to use JPA (code from https://en.wikibooks.org/wiki/Java_Persistence/Criteria):



            // Select the employees and the mailing addresses that have the same address.
            CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
            CriteriaQuery criteriaQuery = criteriaBuilder.createQuery();
            Root employee = criteriaQuery.from(Employee.class);
            Root address = criteriaQuery.from(MailingAddress.class);
            criteriaQuery.multiselect(employee, address);

            criteriaQuery.where( criteriaBuilder.equal(employee.get("address"), address.get("address"));
            Query query = entityManager.createQuery(criteriaQuery);
            List<Object[]> result = query.getResultList();






          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%2f55378871%2feclipselink-namednativequery-pass-column-name-as-parameter-and-not-a-value%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









            1














            Basically it makes no sense to create a prepared query like this, how would you name that query anyway: "*"? So the short answer is: no.




            1. But you could create named queries dynamically if this matches your requirement:



              String colName = "colName";
              String query = "SELECT WHEN " + colName + " IS NULL THEN genre_default";
              Query query = entitymanager.createQuery(query);



            2. Probably using a criteria builder is more the way you want to use JPA (code from https://en.wikibooks.org/wiki/Java_Persistence/Criteria):



              // Select the employees and the mailing addresses that have the same address.
              CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
              CriteriaQuery criteriaQuery = criteriaBuilder.createQuery();
              Root employee = criteriaQuery.from(Employee.class);
              Root address = criteriaQuery.from(MailingAddress.class);
              criteriaQuery.multiselect(employee, address);

              criteriaQuery.where( criteriaBuilder.equal(employee.get("address"), address.get("address"));
              Query query = entityManager.createQuery(criteriaQuery);
              List<Object[]> result = query.getResultList();






            share|improve this answer





























              1














              Basically it makes no sense to create a prepared query like this, how would you name that query anyway: "*"? So the short answer is: no.




              1. But you could create named queries dynamically if this matches your requirement:



                String colName = "colName";
                String query = "SELECT WHEN " + colName + " IS NULL THEN genre_default";
                Query query = entitymanager.createQuery(query);



              2. Probably using a criteria builder is more the way you want to use JPA (code from https://en.wikibooks.org/wiki/Java_Persistence/Criteria):



                // Select the employees and the mailing addresses that have the same address.
                CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
                CriteriaQuery criteriaQuery = criteriaBuilder.createQuery();
                Root employee = criteriaQuery.from(Employee.class);
                Root address = criteriaQuery.from(MailingAddress.class);
                criteriaQuery.multiselect(employee, address);

                criteriaQuery.where( criteriaBuilder.equal(employee.get("address"), address.get("address"));
                Query query = entityManager.createQuery(criteriaQuery);
                List<Object[]> result = query.getResultList();






              share|improve this answer



























                1












                1








                1







                Basically it makes no sense to create a prepared query like this, how would you name that query anyway: "*"? So the short answer is: no.




                1. But you could create named queries dynamically if this matches your requirement:



                  String colName = "colName";
                  String query = "SELECT WHEN " + colName + " IS NULL THEN genre_default";
                  Query query = entitymanager.createQuery(query);



                2. Probably using a criteria builder is more the way you want to use JPA (code from https://en.wikibooks.org/wiki/Java_Persistence/Criteria):



                  // Select the employees and the mailing addresses that have the same address.
                  CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
                  CriteriaQuery criteriaQuery = criteriaBuilder.createQuery();
                  Root employee = criteriaQuery.from(Employee.class);
                  Root address = criteriaQuery.from(MailingAddress.class);
                  criteriaQuery.multiselect(employee, address);

                  criteriaQuery.where( criteriaBuilder.equal(employee.get("address"), address.get("address"));
                  Query query = entityManager.createQuery(criteriaQuery);
                  List<Object[]> result = query.getResultList();






                share|improve this answer













                Basically it makes no sense to create a prepared query like this, how would you name that query anyway: "*"? So the short answer is: no.




                1. But you could create named queries dynamically if this matches your requirement:



                  String colName = "colName";
                  String query = "SELECT WHEN " + colName + " IS NULL THEN genre_default";
                  Query query = entitymanager.createQuery(query);



                2. Probably using a criteria builder is more the way you want to use JPA (code from https://en.wikibooks.org/wiki/Java_Persistence/Criteria):



                  // Select the employees and the mailing addresses that have the same address.
                  CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
                  CriteriaQuery criteriaQuery = criteriaBuilder.createQuery();
                  Root employee = criteriaQuery.from(Employee.class);
                  Root address = criteriaQuery.from(MailingAddress.class);
                  criteriaQuery.multiselect(employee, address);

                  criteriaQuery.where( criteriaBuilder.equal(employee.get("address"), address.get("address"));
                  Query query = entityManager.createQuery(criteriaQuery);
                  List<Object[]> result = query.getResultList();







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered May 27 at 21:10









                Marvin Emil BrachMarvin Emil Brach

                3,5411 gold badge26 silver badges60 bronze badges




                3,5411 gold badge26 silver badges60 bronze badges





















                    Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.







                    Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.



















                    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%2f55378871%2feclipselink-namednativequery-pass-column-name-as-parameter-and-not-a-value%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

                    Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

                    SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

                    은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현