This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin for Android App Development and have Peter Sommerhoff on-line!
See this thread for details.
Win a copy of Kotlin for Android App Development this week in the Kotlin forum!
  • 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
  • Devaka Cooray
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Junilu Lacar
  • Paul Clapham
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • salvin francis
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

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
178
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
178
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
 
All of the world's problems can be solved in a garden - Geoff Lawton. Tiny ad:
RavenDB is an Open Source NoSQL Database that’s fully transactional (ACID) across your database
https://coderanch.com/t/704633/RavenDB-Open-Source-NoSQL-Database
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!