• 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:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • Devaka Cooray
Saloon Keepers:
  • Ganesh Patekar
  • Tim Moores
  • Carey Brown
  • Stephan van Hulst
  • salvin francis
Bartenders:
  • Ron McLeod
  • Frits Walraven
  • Pete Letkeman

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
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!