Hibernate query for entity with map property












2















I've been struggling with a query in hibernate to update the state of an entity. Such entity, called PaymentRequestLink, is in a one to many relation with another entity called extraparameters



PaymentRequestType.java:



@Entity
@Table(name="payment_link")
public class PaymentRequestLink {

private Map<String, ExtraParameter<E>> extraParameters;

@Fetch(FetchMode.SELECT)
@ElementCollection(fetch=FetchType.EAGER)
@CollectionTable(name="extraparameter_payment_link",
schema=BaseEntity.DATABASE_SCHEMA, joinColumns=@JoinColumn(name="extraparameter_payment_link_id"))
@MapKeyColumn(name = "name", length=64, nullable = false)
public Map<String, ExtraParameter<String>> getExtraParameters() {
return extraParameters;
}


ExtraParameter.java:



 @Embeddable
public class ExtraParameter<T extends Serializable> implements Serializable {

//...

@Column(name="extra_type", length=64, nullable=false)
@NotNull
public String getType() {
return type;
}

@Column(name="extra_value", length=255, nullable=false)
@NotNull
public T getValue() {
return value;
}


This is a data example of the extraparameter_payment_link table:



extraparameter_payment_link_id  extra_type           extra_value          name
1 java.sql.Date 2019-01-01 EXPIRATION_DATE


The query I want to make is to update the state of the PaymentRequestLink to EXPIRED when the expiration date, which is stored in the extraparameters, is a date before to the current date.
This is the query I have now:



    String stateSentence = "AND state <> '";
String sqlUpdateLinkDetailed = "UPDATE PaymentRequestLink ld SET state='EXPIRED' " +
"WHERE extraParameters.EXPIRATION_DATE.value <= ? " +
stateSentence + PaymentRequestLinkState.PAID;

Calendar calendar = Calendar.getInstance();
calendar.add(Calendar.MINUTE, 1);
Timestamp now = new Timestamp(calendar.getTimeInMillis());

hibernateTemplate.bulkUpdate(sqlUpdateLinkDetailed, now);


The exception I've got is:



 error processing job
org.springframework.orm.hibernate3.HibernateQueryException: could not resolve property: EXPIRATION_DATE of: component[type,value] [UPDATE
com.some.company.PaymentRequestLink ld SET state='EXPIRED' WHERE extraParameters.EXPIRATION_DATE.value <= ? AND state <> 'PAID']; nested exception is org.hibernate.QueryException: could not resolve property: EXPIRATION_DATE of: component[type,value] [UPDATE com.some.company.PaymentRequestLink ld SET state='EXPIRED' WHERE extraParameters.EXPIRATION_DATE.value <= ? AND state <> 'PAID']


Can anyone help me with this?










share|improve this question















This question has an open bounty worth +50
reputation from Rafael ending tomorrow.


This question has not received enough attention.

















  • Can you show the entire ExtraParameter class?

    – juanlumn
    Jan 21 at 14:19
















2















I've been struggling with a query in hibernate to update the state of an entity. Such entity, called PaymentRequestLink, is in a one to many relation with another entity called extraparameters



PaymentRequestType.java:



@Entity
@Table(name="payment_link")
public class PaymentRequestLink {

private Map<String, ExtraParameter<E>> extraParameters;

@Fetch(FetchMode.SELECT)
@ElementCollection(fetch=FetchType.EAGER)
@CollectionTable(name="extraparameter_payment_link",
schema=BaseEntity.DATABASE_SCHEMA, joinColumns=@JoinColumn(name="extraparameter_payment_link_id"))
@MapKeyColumn(name = "name", length=64, nullable = false)
public Map<String, ExtraParameter<String>> getExtraParameters() {
return extraParameters;
}


ExtraParameter.java:



 @Embeddable
public class ExtraParameter<T extends Serializable> implements Serializable {

//...

@Column(name="extra_type", length=64, nullable=false)
@NotNull
public String getType() {
return type;
}

@Column(name="extra_value", length=255, nullable=false)
@NotNull
public T getValue() {
return value;
}


This is a data example of the extraparameter_payment_link table:



extraparameter_payment_link_id  extra_type           extra_value          name
1 java.sql.Date 2019-01-01 EXPIRATION_DATE


The query I want to make is to update the state of the PaymentRequestLink to EXPIRED when the expiration date, which is stored in the extraparameters, is a date before to the current date.
This is the query I have now:



    String stateSentence = "AND state <> '";
String sqlUpdateLinkDetailed = "UPDATE PaymentRequestLink ld SET state='EXPIRED' " +
"WHERE extraParameters.EXPIRATION_DATE.value <= ? " +
stateSentence + PaymentRequestLinkState.PAID;

Calendar calendar = Calendar.getInstance();
calendar.add(Calendar.MINUTE, 1);
Timestamp now = new Timestamp(calendar.getTimeInMillis());

hibernateTemplate.bulkUpdate(sqlUpdateLinkDetailed, now);


The exception I've got is:



 error processing job
org.springframework.orm.hibernate3.HibernateQueryException: could not resolve property: EXPIRATION_DATE of: component[type,value] [UPDATE
com.some.company.PaymentRequestLink ld SET state='EXPIRED' WHERE extraParameters.EXPIRATION_DATE.value <= ? AND state <> 'PAID']; nested exception is org.hibernate.QueryException: could not resolve property: EXPIRATION_DATE of: component[type,value] [UPDATE com.some.company.PaymentRequestLink ld SET state='EXPIRED' WHERE extraParameters.EXPIRATION_DATE.value <= ? AND state <> 'PAID']


Can anyone help me with this?










share|improve this question















This question has an open bounty worth +50
reputation from Rafael ending tomorrow.


This question has not received enough attention.

















  • Can you show the entire ExtraParameter class?

    – juanlumn
    Jan 21 at 14:19














2












2








2








I've been struggling with a query in hibernate to update the state of an entity. Such entity, called PaymentRequestLink, is in a one to many relation with another entity called extraparameters



PaymentRequestType.java:



@Entity
@Table(name="payment_link")
public class PaymentRequestLink {

private Map<String, ExtraParameter<E>> extraParameters;

@Fetch(FetchMode.SELECT)
@ElementCollection(fetch=FetchType.EAGER)
@CollectionTable(name="extraparameter_payment_link",
schema=BaseEntity.DATABASE_SCHEMA, joinColumns=@JoinColumn(name="extraparameter_payment_link_id"))
@MapKeyColumn(name = "name", length=64, nullable = false)
public Map<String, ExtraParameter<String>> getExtraParameters() {
return extraParameters;
}


ExtraParameter.java:



 @Embeddable
public class ExtraParameter<T extends Serializable> implements Serializable {

//...

@Column(name="extra_type", length=64, nullable=false)
@NotNull
public String getType() {
return type;
}

@Column(name="extra_value", length=255, nullable=false)
@NotNull
public T getValue() {
return value;
}


This is a data example of the extraparameter_payment_link table:



extraparameter_payment_link_id  extra_type           extra_value          name
1 java.sql.Date 2019-01-01 EXPIRATION_DATE


The query I want to make is to update the state of the PaymentRequestLink to EXPIRED when the expiration date, which is stored in the extraparameters, is a date before to the current date.
This is the query I have now:



    String stateSentence = "AND state <> '";
String sqlUpdateLinkDetailed = "UPDATE PaymentRequestLink ld SET state='EXPIRED' " +
"WHERE extraParameters.EXPIRATION_DATE.value <= ? " +
stateSentence + PaymentRequestLinkState.PAID;

Calendar calendar = Calendar.getInstance();
calendar.add(Calendar.MINUTE, 1);
Timestamp now = new Timestamp(calendar.getTimeInMillis());

hibernateTemplate.bulkUpdate(sqlUpdateLinkDetailed, now);


The exception I've got is:



 error processing job
org.springframework.orm.hibernate3.HibernateQueryException: could not resolve property: EXPIRATION_DATE of: component[type,value] [UPDATE
com.some.company.PaymentRequestLink ld SET state='EXPIRED' WHERE extraParameters.EXPIRATION_DATE.value <= ? AND state <> 'PAID']; nested exception is org.hibernate.QueryException: could not resolve property: EXPIRATION_DATE of: component[type,value] [UPDATE com.some.company.PaymentRequestLink ld SET state='EXPIRED' WHERE extraParameters.EXPIRATION_DATE.value <= ? AND state <> 'PAID']


Can anyone help me with this?










share|improve this question














I've been struggling with a query in hibernate to update the state of an entity. Such entity, called PaymentRequestLink, is in a one to many relation with another entity called extraparameters



PaymentRequestType.java:



@Entity
@Table(name="payment_link")
public class PaymentRequestLink {

private Map<String, ExtraParameter<E>> extraParameters;

@Fetch(FetchMode.SELECT)
@ElementCollection(fetch=FetchType.EAGER)
@CollectionTable(name="extraparameter_payment_link",
schema=BaseEntity.DATABASE_SCHEMA, joinColumns=@JoinColumn(name="extraparameter_payment_link_id"))
@MapKeyColumn(name = "name", length=64, nullable = false)
public Map<String, ExtraParameter<String>> getExtraParameters() {
return extraParameters;
}


ExtraParameter.java:



 @Embeddable
public class ExtraParameter<T extends Serializable> implements Serializable {

//...

@Column(name="extra_type", length=64, nullable=false)
@NotNull
public String getType() {
return type;
}

@Column(name="extra_value", length=255, nullable=false)
@NotNull
public T getValue() {
return value;
}


This is a data example of the extraparameter_payment_link table:



extraparameter_payment_link_id  extra_type           extra_value          name
1 java.sql.Date 2019-01-01 EXPIRATION_DATE


The query I want to make is to update the state of the PaymentRequestLink to EXPIRED when the expiration date, which is stored in the extraparameters, is a date before to the current date.
This is the query I have now:



    String stateSentence = "AND state <> '";
String sqlUpdateLinkDetailed = "UPDATE PaymentRequestLink ld SET state='EXPIRED' " +
"WHERE extraParameters.EXPIRATION_DATE.value <= ? " +
stateSentence + PaymentRequestLinkState.PAID;

Calendar calendar = Calendar.getInstance();
calendar.add(Calendar.MINUTE, 1);
Timestamp now = new Timestamp(calendar.getTimeInMillis());

hibernateTemplate.bulkUpdate(sqlUpdateLinkDetailed, now);


The exception I've got is:



 error processing job
org.springframework.orm.hibernate3.HibernateQueryException: could not resolve property: EXPIRATION_DATE of: component[type,value] [UPDATE
com.some.company.PaymentRequestLink ld SET state='EXPIRED' WHERE extraParameters.EXPIRATION_DATE.value <= ? AND state <> 'PAID']; nested exception is org.hibernate.QueryException: could not resolve property: EXPIRATION_DATE of: component[type,value] [UPDATE com.some.company.PaymentRequestLink ld SET state='EXPIRED' WHERE extraParameters.EXPIRATION_DATE.value <= ? AND state <> 'PAID']


Can anyone help me with this?







java hibernate






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Jan 18 at 20:15









RafaelRafael

134114




134114






This question has an open bounty worth +50
reputation from Rafael ending tomorrow.


This question has not received enough attention.








This question has an open bounty worth +50
reputation from Rafael ending tomorrow.


This question has not received enough attention.















  • Can you show the entire ExtraParameter class?

    – juanlumn
    Jan 21 at 14:19



















  • Can you show the entire ExtraParameter class?

    – juanlumn
    Jan 21 at 14:19

















Can you show the entire ExtraParameter class?

– juanlumn
Jan 21 at 14:19





Can you show the entire ExtraParameter class?

– juanlumn
Jan 21 at 14:19












1 Answer
1






active

oldest

votes


















2















Elements of indexed collections (arrays, lists, and maps) can be
referred to by index in a where clause only:




String stateSentence = "AND state <> '";
String sqlUpdateLinkDetailed = "UPDATE PaymentRequestLink ld SET state='EXPIRED' " +
"WHERE extraParameters['EXPIRATION_DATE'].value <= ? " +
stateSentence + PaymentRequestLinkState.PAID;


See HQL expressions documentation for details.






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%2f54260846%2fhibernate-query-for-entity-with-map-property%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









    2















    Elements of indexed collections (arrays, lists, and maps) can be
    referred to by index in a where clause only:




    String stateSentence = "AND state <> '";
    String sqlUpdateLinkDetailed = "UPDATE PaymentRequestLink ld SET state='EXPIRED' " +
    "WHERE extraParameters['EXPIRATION_DATE'].value <= ? " +
    stateSentence + PaymentRequestLinkState.PAID;


    See HQL expressions documentation for details.






    share|improve this answer






























      2















      Elements of indexed collections (arrays, lists, and maps) can be
      referred to by index in a where clause only:




      String stateSentence = "AND state <> '";
      String sqlUpdateLinkDetailed = "UPDATE PaymentRequestLink ld SET state='EXPIRED' " +
      "WHERE extraParameters['EXPIRATION_DATE'].value <= ? " +
      stateSentence + PaymentRequestLinkState.PAID;


      See HQL expressions documentation for details.






      share|improve this answer




























        2












        2








        2








        Elements of indexed collections (arrays, lists, and maps) can be
        referred to by index in a where clause only:




        String stateSentence = "AND state <> '";
        String sqlUpdateLinkDetailed = "UPDATE PaymentRequestLink ld SET state='EXPIRED' " +
        "WHERE extraParameters['EXPIRATION_DATE'].value <= ? " +
        stateSentence + PaymentRequestLinkState.PAID;


        See HQL expressions documentation for details.






        share|improve this answer
















        Elements of indexed collections (arrays, lists, and maps) can be
        referred to by index in a where clause only:




        String stateSentence = "AND state <> '";
        String sqlUpdateLinkDetailed = "UPDATE PaymentRequestLink ld SET state='EXPIRED' " +
        "WHERE extraParameters['EXPIRATION_DATE'].value <= ? " +
        stateSentence + PaymentRequestLinkState.PAID;


        See HQL expressions documentation for details.







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Jan 21 at 19:11

























        answered Jan 21 at 15:05









        SelaronSelaron

        1,61411014




        1,61411014






























            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%2f54260846%2fhibernate-query-for-entity-with-map-property%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

            Liquibase includeAll doesn't find base path

            How to use setInterval in EJS file?

            Petrus Granier-Deferre