-->
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.  [ 1 post ] 
Author Message
 Post subject: JPA/Hibernate not storing @MapKeyColumn's value
PostPosted: Tue Jan 29, 2013 12:56 pm 
Newbie

Joined: Sun Oct 31, 2010 5:18 pm
Posts: 4
Hi,

I have a bi-di Map mapping. Reading works, but Hibernate doesn't store the map key column. When I check in debugger, everything is set as it should.

The INSERT query is:

Code:
insert into rel_custField (field_id, release_id, value, id) values (22, 1, 'fwefwe', 3)

It should also contain set the name column. How should I achieve that?

Maybe the problem is that the map item entity doesn't have the name property? But I have never seen in docs/spec that it should.
If I opted for that solution, I'd have to manually set the name property which seems impractical and redundant.

Code:
@SuppressWarnings("serial")
@Entity @Table(name="`release`")
public class Release implements Serializable, IHasTraits {

    @MapKeyColumn(name = "name")
    @OneToMany(mappedBy = "release", cascade = CascadeType.ALL )
    //@JoinColumn(referencedColumnName = "release_id") // Only at one side.
    private Map<String, ReleaseCustomField> customFields = new HashMap();

    ...
}


and

Code:
@Entity
@Table(name = "rel_custField", uniqueConstraints = {
    @UniqueConstraint(name = "rel_prodcf", columnNames = {"release_id", "field_id"})
})
public class ReleaseCustomField implements Serializable {

    @Id @GeneratedValue( strategy = GenerationType.AUTO )
    private Long id;

    // Make uni-dir?
    @ManyToOne(optional = false)
    @JoinColumn(name = "release_id", nullable = false, updatable = false)
    private Release release;

    ....
}


Thanks, Ondra


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

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.