-->
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: @ElementCollection: bad column names
PostPosted: Tue Aug 31, 2010 1:40 pm 
Newbie

Joined: Thu Jan 22, 2009 6:22 pm
Posts: 5
I have an entity with a collection of embedded components. In JPA, this is indicated with @ElementCollection. This causes two problems. First, the default column names generated for the embedded component (e.g. DDL generation) are syntactically invalid (and do not follow the spec). Second, none of the meta information for the for the embedded component columns are used (e.g. column length, not null, etc).

Here is my code:

Code:
@Entity
public class ATest1 {
   @Id
   private long id;
   
   @ElementCollection @OrderColumn
   List<ATest2> twos = new ArrayList<ATest2>();
}


Code:
@Embeddable
public class ATest2 {
   private String name;
}


When I export the DDL, I get the following:

Quote:
Unsuccessful: create table ATest1_twos (ATest1_id bigint not null, twos_collection&&element_name varchar(255), twos_ORDER integer not null, primary key (ATest1_id, twos_ORDER)) ENGINE=InnoDB


As you can see, Hibernate generates the woefully wrong column name "twos_collection&&element_name" and it is unaware of the NotNull and Size annotations (which work everywhere else).

This affects Hibernate 3.5.2, 3.5.3, and all 3.6.0 betas.

If it means anything, I am using DefaultComponentSafeNamingStrategy. I have tried creating my own naming strategy, but Hibernate ignores it when generating the column names for component collections.

It is worth noting that if I use @Column to specify nullable=false and length=10, those are carried through to the DDL. And if I use @Column to specify an explicit name, that name is used as well. Unfortunately, I plan to embed this component multiple times, so hard-coding column names using @Column won't work for me.

Please tell me I am missing something obvious.

Thank you,

Ted


Top
 Profile  
 
 Post subject: Re: @ElementCollection: bad column names
PostPosted: Sat Sep 25, 2010 5:02 am 
Newbie

Joined: Sat Sep 25, 2010 4:58 am
Posts: 2
Hi Ted,

I'm facing the same issue as you.

Have you find a fix or a workaround since you posted ? Or have you raised a Jira issue ?

Thx,
Johann


Top
 Profile  
 
 Post subject: Re: @ElementCollection: bad column names
PostPosted: Sat Sep 25, 2010 1:44 pm 
Newbie

Joined: Thu Jan 22, 2009 6:22 pm
Posts: 5
Alas no. In order to move on, I simply used @AttributeOverrides to explicit define the name and design of each column. If you build your own database schema, you only have to define the name of the columns.

Obvious, this isn't ideal, nor reusable. But, for my immediate needs it suffices.

Best of Luck.


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.