Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6652131
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T01:05:53+00:00 2026-05-26T01:05:53+00:00

I am struggling trying to persist a map to SQLserver with the code below

  • 0

I am struggling trying to persist a map to SQLserver with the code below and keep getting the following error:

* Caused by: com.microsoft.sqlserver.jdbc.SQLServerException: Invalid object name ‘OnlineReport_availabilities’. *

I use Play framework JPA for this have have managed to persist Maps before with similar code. I tried manually creating the table in the db to see if there was any issue with the name but all seems ok.

I am doing something non conventional or incorrect here?


   @Entity
    public class OnlineReport extends Model {

    @Temporal(TemporalType.DATE)
    public Date date;

    @ElementCollection
    public Map<Date, Double> availabilities;

    public OnlineReport(){
        this.date = new Date();
        this.availabilities = new HashMap<Date, Double>();         
    }

    public void addAvailability(double availability){
        TreeSet<Date> set = new TreeSet(availabilities.entrySet());

        Date lastEntry = null;
        if(!set.isEmpty())
            lastEntry = set.last();

        Date now = new Date();
        if(lastEntry != null){
            //Add availibility every 10mn
            if(DateUtil.getMinutesBetween(lastEntry, now) >= 10){
                availabilities.put(now, availability);
                save();
            }
        } else {
            availabilities.put(now, availability);
            save();
        }
    }
}


Update.

Running JPA in debugSQL I have noticed the following errors:

ERROR ~ Unsuccessful: create table OnlineReport_availabilities (OnlineReport_id numeric(19,0) not null, availabilities double precision null, availabilities_KEY datetime null, primary key (OnlineReport_id, availabilities_KEY))

ERROR ~ Cannot define PRIMARY KEY constraint on nullable column in table 'OnlineReport_availabilities'.

I am under the impression I am missing some annotation definition of 'availabilities'.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T01:05:53+00:00Added an answer on May 26, 2026 at 1:05 am

    Likely you do not have such a table or it is not accessible via connection in use. Are object (tables, fields etc) names case sensitive in db?

    So, after your update we know why you do not have table. Looks like it fails to create not null -constraint to the column that is part of the key. Dialect fails for SQL Server, because your mapping is minimal, but correct. You can try to force it by adding following annotation:

    @MapKeyColumn(columnDefinition = "datetime not null")
    

    Of course having datetime as part of the key will produce problems if it is possible that there is more than one entry per millisecond.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to read the following xml stream but am really struggling. <channelSnapshot
--- Edited below with some more testing, please read :) --- I'm struggling trying
I'm really struggling trying to find something that actually works for getting the basics
I'm struggling with trying to find out why this code isn't working for me.
I'm really struggling to understand why I'm getting this error. I'm getting it referring
I'm struggling trying to teach myself Mockito. Consider the following method, hasInventory() , which
I am struggling trying to build a COM object in Visual Studio (2010) in
I'm struggling with trying to modify some Javascript code. I know what I want
I am struggling trying to perform what I would think would be a relatively
Erlang version: R13B01 Currently I'm struggling trying to make Erlang work with SSL. The

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.