• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

What does @ElementCollection with @Column mean ?

 
Ranch Hand
Posts: 66
MyEclipse IDE Firefox Browser Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 11604
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 66
MyEclipse IDE Firefox Browser Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 11604
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
reply
    Bookmark Topic Watch Topic
  • New Topic