-->
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: Persisting @OneToMany relation
PostPosted: Sun Apr 01, 2012 8:36 pm 
Newbie

Joined: Sun Apr 01, 2012 8:28 pm
Posts: 3
I am having troubles persisting @OneToMany relation in following Entities:

Code:
@Entity
Article {
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;

    @OneToMany(fetch = FetchType.EAGER, cascade=CascadeType.ALL)
    @JoinColumn(name="embed_id", referencedColumnName="id")
    @MapKeyColumn(name = "language")
    @MapKeyEnumerated(EnumType.ORDINAL)
    private Map<Language, Locale> locales;

    public void setLocale(Language l, Locale locale) {
        locale.setLanguage(l);
        locales.put(l, locale);
    }
}


Code:
@Entity
Locale {
    @Id
    private Long embed_id;

    @Id
    private Language language;

    @Column(length = 256)
    private String name;
}


My problem is that when I try to persist the Article, the embed_id field of Locale is still null and I am getting: ERROR: null value in column "embed_id" violates not-null constraint.

To summarize: I am not able to find out how to tell Hibernate to update the embed_id of Locale after persisting Article and having its id.

Thanks for any suggestions!


Top
 Profile  
 
 Post subject: Re: Persisting @OneToMany relation
PostPosted: Mon Apr 02, 2012 10:03 pm 
Newbie

Joined: Sun Apr 01, 2012 8:28 pm
Posts: 3
From the logs I can see, how the ID is correctly generated for Article, but not for Locales - you can see, that embedId stays null:

DEBUG org.hibernate.event.internal.AbstractSaveEventListener - Generated identifier: 87, using strategy: org.hibernate.id.SequenceGenerator

DEBUG org.hibernate.event.internal.AbstractSaveEventListener - Generated identifier: component[language,embedId]{language=0, embedId=null}, using strategy: org.hibernate.id.CompositeNestedGeneratedValueGenerator

DEBUG org.hibernate.event.internal.AbstractSaveEventListener - Generated identifier: component[language,embedId]{language=1, embedId=null}, using strategy: org.hibernate.id.CompositeNestedGeneratedValueGenerator

I am starting to think whether this could be a bug?


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.