question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Date saved but retrieved null in ElementCollection (or Embedded) property

See original GitHub issue

I have an object of type Instance which contains an @ElementCollection of type Datapoint. Each datapoint has a timestamp and a value. In a test, I create some instances with their datapoints and save them, however, when I read any of those instances back from the database, the value for datapoints is set but the timestamp is null.

I am using: Cassandra 3.11.2 Kundera 3.12

persistence.xml

    <persistence-unit name="cassandra_pu">
        <provider>com.impetus.kundera.KunderaPersistence</provider>
        <properties>
            <property name="kundera.nodes" value="localhost"/>
            <property name="kundera.port" value="9042"/>
            <property name="kundera.keyspace" value="d2lablite"/>
            <property name="kundera.dialect" value="cassandra"/>
            <property name="kundera.ddl.auto.prepare" value="create" />
            <property name="kundera.client.lookup.class" value="com.impetus.kundera.client.cassandra.dsdriver.DSClientFactory" />
        </properties>
    </persistence-unit>

Datapoint.java

@Embeddable
public class Datapoint {
    @Column(name="timestamp")
    @Temporal(TemporalType.TIMESTAMP)
    private java.util.Date timestamp;

    @Column(name="value")
    private double value;

    public Datapoint() { }

    // Getters, setters
}

Instance.java

@Entity
@Table(name="instances")
public class Instance {
    @Id
    @Column(name="uuid")
    private String uuid;

    @Column(name="param")
    private String param;

    @ElementCollection
    @Column(name="datapoints")
    private List<Datapoint> datapoints;

    @ElementCollection
    @Column(name="metadata")
    private Map<String, String> metadata;

    @Temporal(TemporalType.TIMESTAMP)
    @Column(name="date")
    private Date date;

    public Instance() { }
}

So what I do is:

  • Create an Instance, create a List<Datapoint>, set it to instance and persist the instance
  • Check via cqlsh that the instance is saved and all datapoints have the timestamp saved as well
  • Use the EntityManager’s find method to fetch an instance by its uuid, and it contains all values, including the date column, and its datapoints contain their values but the timestamp field in every datapoint is null.

I have also tried to use @Embedded and only 1 Datapoint instead of a list and the result is the same, timestamp is null.

What did I miss?

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
devender-yadavcommented, May 28, 2018

Hi @milosjajac,

This issue is fixed and will be available in the next Kundera release.

1reaction
devender-yadavcommented, Apr 17, 2018

Hi @milosjajac,

Seems like an issue from Kundera side.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Hibernate JPA not inserting rows in collection table for null ...
When the collection is retrieved from the database, it has fewer elements than when it was stored because those that are null are...
Read more >
Java Persistence/Embeddables - Wikibooks
TopLink / EclipseLink : Support an embedded reference being null . ... and define property get/set methods for the relationship that set the...
Read more >
JPA - Persisting Collections of embeddable type by ... - LogicBig
Just like the collection of basic type, a collection of embeddable class can be persisted by using @ElementCollection on the collection ...
Read more >
Chapter 7. Collection mapping - Red Hat on GitHub
Two entities cannot share a reference to the same collection instance. Due to the underlying relational model, collection-valued properties do not support null...
Read more >
ElementCollection not updated correctly if the Embeddable ...
With MySQL the DELETE fails to delete any rows where the property is a nullable property and the previous value was null. This...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found