-->
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.  [ 3 posts ] 
Author Message
 Post subject: Nested @Embedded from @ElementCollection ignores annotations
PostPosted: Mon Aug 22, 2011 3:28 pm 
Newbie

Joined: Mon Aug 22, 2011 3:12 pm
Posts: 1
(This behavior is exhibited in 3.5.6-Final, 3.6.5.Final, and 3.6.7.Final).

I'm pretty sure this is a bug, but I'm posting here first in case I've missed something. I'm using Hibernate as a JPA 2 provider with Spring 3.0.5. The idea below is that Parent contains a collection of @Embeddable objects of type A. Class A then further contains another single @Embeddable of type B. The annotations on Parent and A work just fine; the JPA annotations on B are completely ignored (see comments inline on B, below.)

Code:
@Entity
@Table(name="parent")
public class Parent {
    @Id @GeneratedValue   Long id;
    ...

    @ElementCollection(fetch=FetchType.LAZY, targetClass=A.class)
    @CollectionTable(name="a", joinColumns={@JoinColumn(name="parent_id", nullable=false)}
    @ForeignKey(name="a_parent_id_fkey")
    private Collection<A> aObjs = new ArrayList<A>();
    ...
}

@Embeddable
public class A {
    @Column(name="a_string", nullable=false)
    private String aString = "";

    @Embedded
    private B b = new B();
    ...
}

@Embeddable
public class B {

    // This line is ignored: Hibernate's ORM modeling expects this database column to be named "bString",
    // even though the @Column annotation tells it to be "b_string"
    @Column(name="b_string", nullable=false) 
    private String bString;
    ...
}


The example above can sometimes be (poorly) worked around with @AttributeOverride, as long basic types are used with defaults. However, if I add this to B:

Code:
     @Column(name="enum_value", nullable=false)
     @Enumerated(EnumType.STRING)
     private SomeEnum myEnum;


the workaround does not work: the default for enums is to use their ordinal values in the column, and not their string representations - so in this case, I'll have "enum_value VARCHAR(255) NOT NULL" in my database schema, but the Hibernate mapping will expect an integer type for the ordinal value.

The presence or absence of @Embedded on the "B" type in class A does not affect the outcome.

Finally, I know the annotations on class B work - for example, if I have @Entity Parent -> @OneToMany SomeClass -> @Embedded B as my object hierarchy, Hibernate maps the columns using the annotations on B correctly.

Am I missing something, or is this a bug in Hibernate? (JPA 2 defines nested @Embeddables, so I don't see why this shouldn't work.)


Top
 Profile  
 
 Post subject: Re: Nested @Embedded from @ElementCollection ignores annotations
PostPosted: Sat Sep 10, 2011 8:45 am 
Newbie

Joined: Sat Sep 10, 2011 8:41 am
Posts: 1
I'm experiencing the same problem. I'm actually using a custom type (@Type) for the enum. however, (I have debugged through it) hibernate does not pickup the custom type, and instead uses the default EnumType to nullSafeSet the value of the enum...

I there any workaround for this?


Top
 Profile  
 
 Post subject: Re: Nested @Embedded from @ElementCollection ignores annotations
PostPosted: Mon Jan 16, 2012 11:41 am 
Newbie

Joined: Wed Feb 21, 2007 1:48 pm
Posts: 8
Hello, I am facing the same problem after upgrading hibernate from 3.3.2 GA to 3.6.7-FINAL.

Does anyone has a solution or workaround for this?

Will upgrading to a newest version help?

Appreciate a lot the information, thanks.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.