-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Map of String keys to Joda LocalDateTime values
PostPosted: Sat Feb 01, 2014 2:33 am 
Newbie

Joined: Sat Feb 01, 2014 2:17 am
Posts: 2
Hi all,

I'm new to JPA and am running into a problem for which I haven't found an answer yet. I was hoping someone here could lead me in the right direction.

My database (MySQL) is setup as such:

Code:
CREATE TABLE `snapshots` (
    `id` BIGINT(20) NOT NULL,
    PRIMARY KEY (`id`)
) ENGINE = InnoDB;

CREATE TABLE `snapshots_timestamps` (
    `id` BIGINT(20) NOT NULL,
    `key` VARCHAR(50) NOT NULL,
    `value` DATETIME NOT NULL,
    PRIMARY KEY (`id`, `key`)
) ENGINE = InnoDB;


I'm working to create an entity as follows:

Code:
import org.joda.time.LocalDateTime;

@Entity
@Table(name = "snapshots")
public Snapshot {
    private Map<String, LocalDateTime> timestamps;

    @Column(name = "value", nullable = false)
    //@Type(type="org.jadira.usertype.dateandtime.joda.PersistentLocalDateTime")
    @ElementCollection(fetch = FetchType.EAGER)
    @MapKeyColumn(name = "key", nullable = false)
    @Fetch(FetchMode.SELECT)
    @CollectionTable(name = "snapshot_timestamps", joinColumns = @JoinColumn(name = "id"))
    public Map<String, LocalDateTime> getTimestamps() {
        return timestamps;
    }
}


The @Type declaration shown is what I'd normally use if it was a simple column. However, this doesn't seem to work, resulting in the following error when attempting to persist the entity:

Quote:
org.hibernate.engine.jdbc.batch.internal.AbstractBatchImpl release
INFO: HHH000010: On release of batch it still contained JDBC statements


The entity does not persist.

So I know I'm doing something wrong. I'm really hoping it's something simple, but will appreciate whatever guidance the community can provide.

Thanks so much!

Chris


Top
 Profile  
 
 Post subject: Re: Map of String keys to Joda LocalDateTime values
PostPosted: Mon Feb 03, 2014 7:14 pm 
Newbie

Joined: Sat Feb 01, 2014 2:17 am
Posts: 2
I was able to solve this using the targetClass attribute of the ElementCollection annotation.

Chris


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.