Win a copy of The Journey To Enterprise Agility this week in the Agile and Other Processes forum! And see the welcome thread for 20% off.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

What does @ElementCollection with @Column mean ?  RSS feed

 
Ranch Hand
Posts: 65
Firefox Browser MyEclipse IDE Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have come across this piece of code -:



From the Oracle documentation over here http://docs.oracle.com/javaee/6/api/javax/persistence/CollectionTable.html

Why specify @Column after @ElementCollection what does that mean ?

I have used the following pattern in my code and I have noticed no difference whatsoever. So why use it ?
 
Sheriff
Posts: 11338
177
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When I have a doubt about JPA, I always check the Java Persistence Wikibook first. Most of the time my doubts are cleared, it's really an awesome resource! Here is the page about ElementCollection (and @CollectionTable) which also has an example of @ElementCollection followed by @Column.
 
Sreyan Chakravarty
Ranch Hand
Posts: 65
Firefox Browser MyEclipse IDE Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Roel De Nijs wrote:When I have a doubt about JPA, I always check the Java Persistence Wikibook first. Most of the time my doubts are cleared, it's really an awesome resource! Here is the page about ElementCollection (and @CollectionTable) which also has an example of @ElementCollection followed by @Column.



So correct me if I am wrong here. @Column is used to specify the name of that column which is created in the sub table ? In the above example the column will be named "name" and the value will be varchar(50) right ?
 
Roel De Nijs
Sheriff
Posts: 11338
177
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Sreyan Chakravarty wrote:@Column is used to specify the name of that column which is created in the sub table ? In the above example the column will be named "name" and the value will be varchar(50) right ?


That's indeed my understanding as well!

It's used when you have a basic collection (that's a collection of strings, integers,...). Then @Column will be the name of the column where the strings, integers,... will be stored. With a complex type (like Phone), the column names will be mapped in the Phone class (and you'll use the @Column in this class).

Hope it helps!
Kind regards,
Roel
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!